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 2005 Forums
 Transact-SQL (2005)
 Update error Incorrect syntax near '<'.

Author  Topic 

dand_dd
Starting Member

6 Posts

Posted - 2011-03-04 : 06:53:51
Hi,

I have a table with 4 columns: ID, Date1, Date2 and Value
I want to make an Update to Value field based on the difference between Date1 and Date2.

if difference < 6 then Value = 1
if difference between 6 and 10 then Value = 2
else value = 3

What's it's wrong here?

Update table_name set Value= (Select ID,date1,Date2, 
Value= case Datediff(day, Date1,Date2)
When Value < 6 then '1'
When Value between 6 and 10 then '2'
else '3'
end,
From table_name


Thank's

vaibhavktiwari83
Aged Yak Warrior

843 Posts

Posted - 2011-03-04 : 07:10:21
Try this -


Update table_name set value=
case
When Datediff(day, Date1,Date2) < 6 then '1'
When Datediff(day, Date1,Date2) between 6 and 10 then '2'
else '3' end
FROM table_name



Vaibhav T

If I cant go back, I want to go fast...
Go to Top of Page
   

- Advertisement -