Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 Update Statement Help

Author  Topic 

Sonu619
Posting Yak Master

202 Posts

Posted - 2011-05-18 : 13:47:05
Hi Guys,

Update help,
Here is my data
ID# VALUE
C-1234 NULL
M-3456 NULL

After I run update statement end result should be like this
ID# VALUE
C-1234 M-3456
M-3456 NULL

Thanks for Help.

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-18 : 14:03:33
Is there some field in your table that orders the data? There has to be some way to determine that M-3456 is right "below" C-1234


Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Sonu619
Posting Yak Master

202 Posts

Posted - 2011-05-18 : 14:25:12
Here is my data
ID# VALUE ID
C-1234 NULL 1
M-3456 NULL 2

IF SOMETHING LIKE THIS THEN?
Go to Top of Page

jimf
Master Smack Fu Yak Hacker

2875 Posts

Posted - 2011-05-18 : 15:08:46
This will produce your original expected output

select t1.ID#,t2.# as [Value]
from yourTable t1
left join yourTable t2 on t1.id = t2.id - 1

Jim

Everyday I learn something that somebody else already knew
Go to Top of Page

Sonu619
Posting Yak Master

202 Posts

Posted - 2011-05-23 : 11:50:48
Jim thanx for your help, Here is the situation and need your advise,
I have sample data like this
ID# VALUE ID
C-1234 NULL 84
M-3456 NULL 106

Note:- ID column is not consistance. Please advise.
Go to Top of Page
   

- Advertisement -