If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Microsoft SQL Server > write a sql select

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-19-11, 04:29
mau5000 mau5000 is offline
Registered User
 
Join Date: Feb 2011
Posts: 2
Red face 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
Reply With Quote
  #2 (permalink)  
Old 02-19-11, 05:44
Jack Vamvas Jack Vamvas is offline
Registered User
 
Join Date: Jan 2009
Posts: 57
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
__________________
-------------
DBA DB2
SQL SERVER DBA

Last edited by Jack Vamvas; 02-19-11 at 05:49.
Reply With Quote
  #3 (permalink)  
Old 02-21-11, 07:14
Wim Wim is offline
Registered User
 
Join Date: Nov 2004
Posts: 1,279
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/2008/2008 R2 Earned beers: 16
Wim
Beware of bugs in the above code; I have only proved it correct, not tried it. -- Donald Knuth
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
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On