Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Update value in same table

Status
Not open for further replies.

cbsm

Programmer
Oct 3, 2002
229
FR
I am getting crazy !
I have a table like this:
Table TEST(
Date1 datetime,
Price float Null)
I fill the table with the days of the month.
And update the table with the right price for the day.
For some days, I do not have a price, and I want to get the price from the day before.
This sounds quite simple, I do not manage to find a solution !
This is (a selection of) what I already tried :

update TEST
set Price = t2.Price
from TEST t2
where Date1 = dateadd(dd,-1,t2.Date1)
and Price=NULL
=> nothing

update TEST
set Price = (select t2.Price from TEST t2 where Date1 = dateadd(dd,-1,t2.Date1))
where Price=NULL
=> Says one row was updated - but my table lokk the same !
Thank you !
 
got it !

update TEST
set Price = (select t2.Price from TEST t2 where TEST.Date1 = dateadd(dd,+1,t2.Date1))
where Price=NULL
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top