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

SQL QUERY PROBLEM..

Scheduled Pinned Locked Moved Database
helpdatabase
19 Posts 8 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.
  • A Aman786Singh

    Try this one... select productname,sum(issueqty) QTY from issuance where issuedate >= '5/1/2010' and issuedate <= '5/31/2010' and productid in ('777' ,'778') group by productname order by productname

    M Offline
    M Offline
    mjawadkhatri
    wrote on last edited by
    #5

    Thanks

    1 Reply Last reply
    0
    • M mjawadkhatri

      yes all record of productid=777 and productid=778

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

      You want the records that have number "777" or "778". You are asking for the records that have *both* numbers. The resulting list will have records with both records containing 777 AND 778, but you'll need to ask for the records that contain 777 OR 778 :)

      I are Troll :suss:

      1 Reply Last reply
      0
      • M mjawadkhatri

        yes all record of productid=777 and productid=778

        T Offline
        T Offline
        Tim Carmichael
        wrote on last edited by
        #7

        In high school, to drive home the difference between 'AND' and 'OR' in a logical statement, the teacher asked all of the students in room 201 and 202 to please stand up. When people stood, he asked if there body was split, thereby allowing them to be in two rooms at the same time.

        L 1 Reply Last reply
        0
        • A Aman786Singh

          Try this one... select productname,sum(issueqty) QTY from issuance where issuedate >= '5/1/2010' and issuedate <= '5/31/2010' and productid in ('777' ,'778') group by productname order by productname

          T Offline
          T Offline
          Tom Deketelaere
          wrote on last edited by
          #8

          Actually he shouldn't use that type of date format since it can fail. Better is to use the SQL standard: yyyyMMdd

          select productname,sum(issueqty) QTY from issuance
          where issuedate >= '20100501' and issuedate <= '20100531'
          and productid in ('777' ,'778')
          group by productname
          order by productname

          N 1 Reply Last reply
          0
          • T Tom Deketelaere

            Actually he shouldn't use that type of date format since it can fail. Better is to use the SQL standard: yyyyMMdd

            select productname,sum(issueqty) QTY from issuance
            where issuedate >= '20100501' and issuedate <= '20100531'
            and productid in ('777' ,'778')
            group by productname
            order by productname

            N Offline
            N Offline
            Not Active
            wrote on last edited by
            #9

            Tom Deketelaere wrote:

            that type of date format since it can fail.

            Can you elaborate? What would allow or cause it to fail?


            I know the language. I've read a book. - _Madmatt

            I T 2 Replies Last reply
            0
            • T Tim Carmichael

              In high school, to drive home the difference between 'AND' and 'OR' in a logical statement, the teacher asked all of the students in room 201 and 202 to please stand up. When people stood, he asked if there body was split, thereby allowing them to be in two rooms at the same time.

              L Offline
              L Offline
              Luc Pattyn
              wrote on last edited by
              #10

              and that is when the class decided to tear down the wall between rooms 201 and 202 I presume. :laugh:

              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


              I only read formatted code with indentation, so please use PRE tags for code snippets.


              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


              T 1 Reply Last reply
              0
              • N Not Active

                Tom Deketelaere wrote:

                that type of date format since it can fail.

                Can you elaborate? What would allow or cause it to fail?


                I know the language. I've read a book. - _Madmatt

                I Offline
                I Offline
                i j russell
                wrote on last edited by
                #11

                In the UK, the date '5/31/2010' would fail if you localize the database because we format dates as dd/mm/yyyy. Using yyyymmdd format or explicitly using CONVERT is much safer.

                N 1 Reply Last reply
                0
                • N Not Active

                  Tom Deketelaere wrote:

                  that type of date format since it can fail.

                  Can you elaborate? What would allow or cause it to fail?


                  I know the language. I've read a book. - _Madmatt

                  T Offline
                  T Offline
                  Tim Carmichael
                  wrote on last edited by
                  #12

                  At a guess, regional settings: 5/1/2010 can be interpreted as 01-May-2010 or 05-Jan-2010 The second date, 5/31/2010, is presumed to mean '31-May-2010' and provides context for the first date. I encounter this issue on a regular basis; especially when 'constructing' datetime stamps on the fly. For example, our mill production day starts at 7:00 AM. For for month to date information for a given date, I have to build the date as: '01-' (month of given date) '-' (year of given date). Hope that helps. Tim

                  N 1 Reply Last reply
                  0
                  • I i j russell

                    In the UK, the date '5/31/2010' would fail if you localize the database because we format dates as dd/mm/yyyy. Using yyyymmdd format or explicitly using CONVERT is much safer.

                    N Offline
                    N Offline
                    Not Active
                    wrote on last edited by
                    #13

                    I guess that falls under the DAH!! category. Obviously if you are using dates they must be in the correct format :rolleyes: Using universal time will ensure these issues do not arise. '20100501' is just as likely to be mistyped and cause issues.


                    I know the language. I've read a book. - _Madmatt

                    1 Reply Last reply
                    0
                    • T Tim Carmichael

                      At a guess, regional settings: 5/1/2010 can be interpreted as 01-May-2010 or 05-Jan-2010 The second date, 5/31/2010, is presumed to mean '31-May-2010' and provides context for the first date. I encounter this issue on a regular basis; especially when 'constructing' datetime stamps on the fly. For example, our mill production day starts at 7:00 AM. For for month to date information for a given date, I have to build the date as: '01-' (month of given date) '-' (year of given date). Hope that helps. Tim

                      N Offline
                      N Offline
                      Not Active
                      wrote on last edited by
                      #14

                      The implication I read was the OP said it would fail because of SQL server issue. Of course you must use the proper date format. That's user error not a SQL Server issue


                      I know the language. I've read a book. - _Madmatt

                      T 1 Reply Last reply
                      0
                      • N Not Active

                        The implication I read was the OP said it would fail because of SQL server issue. Of course you must use the proper date format. That's user error not a SQL Server issue


                        I know the language. I've read a book. - _Madmatt

                        T Offline
                        T Offline
                        Tom Deketelaere
                        wrote on last edited by
                        #15

                        No I mend for the exact reason Tim talks about. Sorry if that wasn't entirely clear :) I encounter this a lot. Very often ours clients pc will be set to the correct regional settings (Belgium settings) but there server (installed by hardware guys) is almost always set to the English settings, so without using the SQL standard format things can go very wrong and act very weird.

                        1 Reply Last reply
                        0
                        • L Luc Pattyn

                          and that is when the class decided to tear down the wall between rooms 201 and 202 I presume. :laugh:

                          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                          I only read formatted code with indentation, so please use PRE tags for code snippets.


                          I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                          T Offline
                          T Offline
                          Tom Deketelaere
                          wrote on last edited by
                          #16

                          Not to be picky here but wouldn't that just merge the 2 rooms into 1 room and therefor they once again weren't in 201 AND 202 but only in 201 OR 202 (or another number given to the now twice as big a room :) )

                          L 1 Reply Last reply
                          0
                          • T Tom Deketelaere

                            Not to be picky here but wouldn't that just merge the 2 rooms into 1 room and therefor they once again weren't in 201 AND 202 but only in 201 OR 202 (or another number given to the now twice as big a room :) )

                            L Offline
                            L Offline
                            Luc Pattyn
                            wrote on last edited by
                            #17

                            Of course not. Without the wall, they would be in both rooms at the same time. Unless you insist on renumbering everything, or otherwise denormalize the school. :)

                            Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                            I only read formatted code with indentation, so please use PRE tags for code snippets.


                            I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                            T 1 Reply Last reply
                            0
                            • L Luc Pattyn

                              Of course not. Without the wall, they would be in both rooms at the same time. Unless you insist on renumbering everything, or otherwise denormalize the school. :)

                              Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles]


                              I only read formatted code with indentation, so please use PRE tags for code snippets.


                              I'm not participating in frackin' Q&A, so if you want my opinion, ask away in a real forum (or on my profile page).


                              T Offline
                              T Offline
                              Tom Deketelaere
                              wrote on last edited by
                              #18

                              Well if you keep the numbering that would mean 201 is one half of the room and 202 another half of the room. One could argue that in order to be in both rooms at the same time you would have to be standing in the exact middle of the room (where the wall was). I don't know why but I'm in a picky mood today, must be because of the slow day at work ;P

                              L 1 Reply Last reply
                              0
                              • T Tom Deketelaere

                                Well if you keep the numbering that would mean 201 is one half of the room and 202 another half of the room. One could argue that in order to be in both rooms at the same time you would have to be standing in the exact middle of the room (where the wall was). I don't know why but I'm in a picky mood today, must be because of the slow day at work ;P

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

                                Tom Deketelaere wrote:

                                I don't know why but I'm in a picky mood today

                                The example shows that picky is what's being trained - since the devil is always in the details :)

                                I are Troll :suss:

                                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