SQL Query Help!
-
Hi All, Im sure this is very simple but after googling for the past 4 hours i cannot seem to find the correct syntax. I currenly have a SQL which amongst other tables has a DateTime Coloum in the folllowing Format: 2013-09-11 21:06:08:970 I am currently running the follow query from within my C# Application: select * from table where errorcode = 448 What I would like to do is: select * from table where errorcode = 448, where date = today and also select * from table where errorcode = 448, where date is between 2013-09-11 00:00:00:000 and 2013-09-11 23:59:59:999 I just cant figure out the correct syntax for the queries though. Could anybody possible Help? Many Thanks SG
-
Hi All, Im sure this is very simple but after googling for the past 4 hours i cannot seem to find the correct syntax. I currenly have a SQL which amongst other tables has a DateTime Coloum in the folllowing Format: 2013-09-11 21:06:08:970 I am currently running the follow query from within my C# Application: select * from table where errorcode = 448 What I would like to do is: select * from table where errorcode = 448, where date = today and also select * from table where errorcode = 448, where date is between 2013-09-11 00:00:00:000 and 2013-09-11 23:59:59:999 I just cant figure out the correct syntax for the queries though. Could anybody possible Help? Many Thanks SG
Ah, see this where to post it, not the C# forum, and now you've cross-posted. Very naughty.
-
Hi All, Im sure this is very simple but after googling for the past 4 hours i cannot seem to find the correct syntax. I currenly have a SQL which amongst other tables has a DateTime Coloum in the folllowing Format: 2013-09-11 21:06:08:970 I am currently running the follow query from within my C# Application: select * from table where errorcode = 448 What I would like to do is: select * from table where errorcode = 448, where date = today and also select * from table where errorcode = 448, where date is between 2013-09-11 00:00:00:000 and 2013-09-11 23:59:59:999 I just cant figure out the correct syntax for the queries though. Could anybody possible Help? Many Thanks SG
Member 10266943 wrote:
Im sure this is very simple but after googling for the past 4 hours i cannot seem to find the correct syntax.
The syntax is defined in the manual. Google is a general search-engine, and whilst it's helpfull when researching a new topic, it's not the place to be when you simply need a manual.
Member 10266943 wrote:
What I would like to do is:
select * from table where errorcode = 448, where date = todayYou'd need to pick up a book on SQL. A statement has a single
WHERE
clause, and we add in more filters using theAND
keyword. Something similar to below;SELECT col1, col2
FROM sometable
WHERE errorcode = 448
AND somedate = GETDATE()There shouldn't be any columns in the table named "date" as it's a non-descriptive name. Also, "table" and "date" are reserved keywords.
Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]
-
Hi All, Im sure this is very simple but after googling for the past 4 hours i cannot seem to find the correct syntax. I currenly have a SQL which amongst other tables has a DateTime Coloum in the folllowing Format: 2013-09-11 21:06:08:970 I am currently running the follow query from within my C# Application: select * from table where errorcode = 448 What I would like to do is: select * from table where errorcode = 448, where date = today and also select * from table where errorcode = 448, where date is between 2013-09-11 00:00:00:000 and 2013-09-11 23:59:59:999 I just cant figure out the correct syntax for the queries though. Could anybody possible Help? Many Thanks SG
I'm sure I don't understand the question because if you query using "WHERE [date] = '%2013-09-11%'" without any time appendix dangling from it the return will give all strings of the wildcarded nature. Incidently, noone knows the storage datatype of [date] but the programmer who coded the procedure.
Member 10266943 wrote:
the folllowing Format
Really?
Member 10266943 wrote:
2013-09-11 21:06:08:970
Check the format in Object Viewer ...
-
Hi All, Im sure this is very simple but after googling for the past 4 hours i cannot seem to find the correct syntax. I currenly have a SQL which amongst other tables has a DateTime Coloum in the folllowing Format: 2013-09-11 21:06:08:970 I am currently running the follow query from within my C# Application: select * from table where errorcode = 448 What I would like to do is: select * from table where errorcode = 448, where date = today and also select * from table where errorcode = 448, where date is between 2013-09-11 00:00:00:000 and 2013-09-11 23:59:59:999 I just cant figure out the correct syntax for the queries though. Could anybody possible Help? Many Thanks SG
Check out this: The ultimate guide to the datetime datatypes[^] And to select everything form today you can use something like this: SELECT * FROM table WHERE DATEDIFF(day, date, Getdate())=0