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.
Author |
Topic |
petek
Posting Yak Master
192 Posts |
Posted - 2010-11-11 : 05:01:25
|
Hi i need to create a SQL statement to output a 1 or 0 depending on the value from the query.the query i have is:SELECT DATEDIFF(minute, ServerLastAccessDate, getdate()) AS Mins FROM timegate what i need is if Mins is greater than 20 then return a 1 else 0Is this possible?i tried the case staement but am not having any joy...your help will be appreciatedcheersPeteKind RegardsPete. |
|
Sachin.Nand
2937 Posts |
Posted - 2010-11-11 : 05:04:08
|
[code]SELECT case when DATEDIFF(minute, ServerLastAccessDate, getdate()) >20 then 1 else 0AS Mins FROM timegate [/code]PBUH |
 |
|
petek
Posting Yak Master
192 Posts |
Posted - 2010-11-11 : 05:10:29
|
hi Sachin....thanks for the reply but i get:Msg 156, Level 15, State 1, Line 3Incorrect syntax near the keyword 'AS'.Kind RegardsPete. |
 |
|
petek
Posting Yak Master
192 Posts |
Posted - 2010-11-11 : 05:18:08
|
Hi missing an END....SELECT case when DATEDIFF(minute, ServerLastAccessDate, getdate()) >20 then 1 else 0 end as 'Mins' FROM timegateKind RegardsPete. |
 |
|
Sachin.Nand
2937 Posts |
Posted - 2010-11-11 : 05:39:17
|
quote: Originally posted by petek Hi missing an END....SELECT case when DATEDIFF(minute, ServerLastAccessDate, getdate()) >20 then 1 else 0 end as 'Mins' FROM timegateKind RegardsPete.
Yup.I missed the END part.PBUH |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2010-11-11 : 06:36:12
|
quote: Originally posted by petek Hi missing an END....SELECT case when DATEDIFF(minute, ServerLastAccessDate, getdate()) >20 then 1 else 0 end as 'Mins' FROM timegateKind RegardsPete.
Also dont use single quotes around alias nameMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|