Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2011
    Posts
    2

    Red face Unanswered: write a sql select

    please, i need help.

    in my DB i've this situation:

    column1|column2|column3|column4|column5|column6
    ABC|22222222|null|33333333|33333333|44444444
    DEF|11111111|77777777|11111111|null|77777777
    GHI|88888888|null|null|99999999|00000000

    and in need to transform in:

    column1|column2|column3|column4|column5|column6
    ABC|22222222|33333333|44444444|null|null
    DEF|11111111|77777777|null|null|null
    GHI|88888888|99999999|00000000|null

    tk a lot.
    Mau5000

  2. #2
    Join Date
    Jan 2009
    Location
    United Kingdom
    Posts
    77
    Create a copy of the table, then write a series of UPDATE statements.
    Such as :=
    UPDATE mytable SET col3 = col4,col4 = 6 ,assuming that is the correct pattern

    As long as there is a pattern , then this should work.=
    Ensure you've backedup prior to starting
    Last edited by Jack Vamvas; 02-19-11 at 06:49.

  3. #3
    Join Date
    Nov 2004
    Posts
    1,427
    Provided Answers: 4
    When you can write the contents of Column3, Column4, ... column6 in Column2, that means they all contain the same kind of data.

    Your database should be normalised:
    column1|column2|column3|column4|column5|column6
    should be normalised into:
    column1|column2

    ABC|22222222|null|33333333|33333333|44444444
    Will become:
    ABC|22222222
    ABC|33333333
    ABC|33333333
    ABC|44444444

    GHI|88888888|null|null|99999999|00000000
    Will become
    GHI|88888888
    GHI|99999999
    GHI|00000000
    With kind regards . . . . . SQL Server 2000/2005/2012
    Wim

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •