views:

41

answers:

1

I'm working with SQL Server and I'm pretty new to SQL in general, so if this is a very trivial question, please bear with me.

I have a table in a database with a datetime field representing some timestamp. When extracting the table via a SELECT statement, I would like to have a column of True/False representing whether or not the row has been updated since some given time.

I've tried something like:

"SELECT val1, val2, FORMAT(LastTimestamp > " + GivenTime + ", 'True/False')" +
"FROM table"

I've gotten something similar to work on the w3 online query tester, but I think that may be in MySQL and I was unable to test datetimes. The database right now seems to complain about the > symbol.

Anyone know the proper query string?

+5  A: 

something like:

select val1, val2, 
case when LastTimestamp > '20100720' then 'True' else 'False' end as [True/False] 
from Table

Note that in the above I've used a date literal which breaks down into 'yyyymmdd'

Yellowfog
I get the following errors from this:Error in SELECT clause: expression near '>'.Error in SELECT clause: expression near 'FROM'.Missing FROM clause.Unable to parse query text.
@user - Looking at your original query I think you're putting it in quotes. That might explain why there is a missing FROM near FROM at least! You don't need to do that. as YellowFrog has written it above should work fine.
Martin Smith
Agreed, YellowFrog's query looks fine
LittleBobbyTables
Hey, it works! :) . Turns out I forgot the when.
Hey, you guys, it's yellowFOG. YellowFROG, sheesh: what a stupid name.
Yellowfog
+1: Well done, FallowYog
OMG Ponies