Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. SQL Query Help!

SQL Query Help!

Scheduled Pinned Locked Moved Database
databasecsharphelpquestion
5 Posts 5 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10236377
    wrote on last edited by
    #1

    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

    P L R M 4 Replies Last reply
    0
    • U User 10236377

      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

      P Offline
      P Offline
      PIEBALDconsult
      wrote on last edited by
      #2

      Ah, see this where to post it, not the C# forum, and now you've cross-posted. Very naughty.

      1 Reply Last reply
      0
      • U User 10236377

        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

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        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 = today

        You'd need to pick up a book on SQL. A statement has a single WHERE clause, and we add in more filters using the AND 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[^]

        1 Reply Last reply
        0
        • U User 10236377

          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

          R Offline
          R Offline
          RedDk
          wrote on last edited by
          #4

          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 ...

          1 Reply Last reply
          0
          • U User 10236377

            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

            M Offline
            M Offline
            Malte Klena
            wrote on last edited by
            #5

            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

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups