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 2000 Forums
 Transact-SQL (2000)
 shift down one row

Author  Topic 

dirwin26
Yak Posting Veteran

81 Posts

Posted - 2005-12-14 : 18:09:26
I want to take column B and shift it down one value
Here's what I have:
Thedate----ColA----ColB
today------1--------2
tomorrow---2--------XX
Here's where I want to get to:
Thedate----ColA----ColB
today------1--------XX
tomorrow---2--------2

Does anyone know how to do this??
Thanks

X002548
Not Just a Number

15586 Posts

Posted - 2005-12-14 : 21:09:59
The order of data in a database has no meaning

Pleas read the link in my sig and post what it asks

you will get an answer in minutes



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2005-12-15 : 02:20:31
Where do you want to show these data?
If you use Front End application, show these there

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2005-12-15 : 02:40:36
quote:
Here's what I have:
Thedate----ColA----ColB
today------1--------2
tomorrow---2--------XX
Here's where I want to get to:
Thedate----ColA----ColB
today------1--------XX
tomorrow---2--------2



What are you trying to achieve ?
Are you swaping the ColB's value for today and tomorrow ?
Your sample data is too few to understand your requirement.

-----------------
[KH]

Learn something new everyday
Go to Top of Page

dirwin26
Yak Posting Veteran

81 Posts

Posted - 2005-12-15 : 10:23:09
By shifting the data down one row, which in this case does matter b/c the primaryKey col is dates, I can assign a closing value of today to tomorrow. This gets it done.


update #res
set dateb = dateadd(day,1,thedate)

update #res
set colb = r1.cola
from #res r1
where r1.dateb = #res.thedate
Go to Top of Page
   

- Advertisement -