There is something wrong with these queries I think. Can you see what I am doing wroong please? Thanks Let's say today's date is 26 April 2012 Query number 1 should return 1 row whereas it does not Query number 2 should NOT return any row whereas it does
1- SELECT Field1, Field2, Field3 FROM tblMain WHERE Field1 = 'xxx' AND ( '26/04/2012' < ('03/05/2012'))
2- SELECT Field1, Field2, Field3 FROM tblMain WHERE Field1 = 'xxx' AND ( '26/04/2012' > ('03/05/2012'))
It is doing a string comparison because SQL doesn't know that you want it to be converted to dates. Cast at least one side to date/datetime. Also, preferably, use unambiguous date formatting (YYYYMMDD).
Can you see what is wrong with this query please? It says incorrect syntx next ) which is pointing to the last ) Thanks set @criteriaOR = replace(@criteriaOR, 'tradedate', 'convert(datetime, ' + char(39) + convert(varchar(11), getdate(), 103) + char(39) + ')' + )