Click here to Skip to main content
15,891,717 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I use the following formula for my computed column Delay :
SQL
(case [IsReturned] when (0) then datediff(minute,dateadd(day,[Time],[StartDate]),getdate())  end)


it works correctly when the IsReturned column is 0, but when this IsReturned column is 1 the Delay column becomes null and I don not want this value to become null. I need to change this formula that don`t change the delay value if IsReturned = 1.

Thanks
Posted

Try this
SQL
delay = case when [IsReturned] = 0 then datediff(minute,dateadd(day,[Time],[StartDate]),getdate())  else delay end
 
Share this answer
 
Comments
Pedram Parsian 5-Jan-15 4:04am    
it will not work because it made a loop ...
CHill60 5-Jan-15 4:07am    
What loop?? Works fine for me
Pedram Parsian 5-Jan-15 4:11am    
Computed column 'Delay' in table 'Circulation' is not allowed to be used in another computed-column definition. it is the error.
CHill60 5-Jan-15 4:36am    
Have you defined the computed column as "Persisted"?
Have you considered using a Function to calculate the value?
Does this have to be a computed column (i.e. could the delay be calculated as and when the database is queried)
hi Try this

SQL
(case [IsReturned] when (0) then datediff(minute,dateadd(day,[Time],[StartDate]),getdate()) else 1 end)
 
Share this answer
 
Comments
Pedram Parsian 5-Jan-15 4:07am    
hello, I don't want to replace 1. I want to keep the last value.
Sumit Jawale 5-Jan-15 4:12am    
then use your column as it is.. I guess delay is your column which you want to keep as it is.

(case [IsReturned] when (0) then datediff(minute,dateadd(day,[Time],[StartDate]),getdate()) else delay end)
Pedram Parsian 5-Jan-15 4:29am    
I already said, it doesn't work.
Sumit Jawale 5-Jan-15 4:35am    
ok. Use ISNULL in your select
ISNULL((case [IsReturned] when (0) then datediff(minute,dateadd(day,[Time],[StartDate]),getdate()) end),delay)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900