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
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. Web Development
  3. ASP.NET
  4. sql query for dropdownlist

sql query for dropdownlist

Scheduled Pinned Locked Moved ASP.NET
databasequestion
11 Posts 4 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.
  • E eyeseetee

    Hi guys I need to write the following sql query: select * from table where field1 not in (select field2 from table2 where field3 like '%05/09/2008%' and sum (field3) < 1) Basically I need to put a sum in the where statement, is it possible to do this? thanks :)

    The answers posted by me are suggestions only and cannot be used in anyway against me.

    D Offline
    D Offline
    Dilip H Patel
    wrote on last edited by
    #2

    Dear .netman, first of all you can not use aggregate functions (like sum, avg) without using Group by clause. and another thing also you can not use aggregate functions in where clause. you have to use Having clause with group by clause. select * from table where field1 not in (select field2 from table2 where field3 like '%05/09/2008%' gruop by field2 having sum (field3) < 1) Regards, Dilip Patel

    1 Reply Last reply
    0
    • E eyeseetee

      Hi guys I need to write the following sql query: select * from table where field1 not in (select field2 from table2 where field3 like '%05/09/2008%' and sum (field3) < 1) Basically I need to put a sum in the where statement, is it possible to do this? thanks :)

      The answers posted by me are suggestions only and cannot be used in anyway against me.

      B Offline
      B Offline
      Blue_Boy
      wrote on last edited by
      #3

      try this select * from table where field1 not in (select field2 from table2 where field3 like '%05/09/2008%' and (select top 1 sum(t1.field3) from table2 as t1 where t1.field3= table2.field3 group by t1.field3) < 1


      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

      E 1 Reply Last reply
      0
      • B Blue_Boy

        try this select * from table where field1 not in (select field2 from table2 where field3 like '%05/09/2008%' and (select top 1 sum(t1.field3) from table2 as t1 where t1.field3= table2.field3 group by t1.field3) < 1


        I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

        E Offline
        E Offline
        eyeseetee
        wrote on last edited by
        #4

        Hi OK Im not sure how to write this query but Im going to explain because the code above works but it doesnt do what I want. Basically I need to do check how many rows in another table contain the number 2 and match a certain date. so something like select * from table where field1 not in (select field2 from table2 where field3 like '%05/09/2008%' and sum number of fields containing '2' < 1) any help on this would be great thanks

        The answers posted by me are suggestions only and cannot be used in anyway against me.

        B 1 Reply Last reply
        0
        • E eyeseetee

          Hi OK Im not sure how to write this query but Im going to explain because the code above works but it doesnt do what I want. Basically I need to do check how many rows in another table contain the number 2 and match a certain date. so something like select * from table where field1 not in (select field2 from table2 where field3 like '%05/09/2008%' and sum number of fields containing '2' < 1) any help on this would be great thanks

          The answers posted by me are suggestions only and cannot be used in anyway against me.

          B Offline
          B Offline
          Blue_Boy
          wrote on last edited by
          #5

          Which result you get from my query and which result you want to get?


          I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

          E 1 Reply Last reply
          0
          • B Blue_Boy

            Which result you get from my query and which result you want to get?


            I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

            E Offline
            E Offline
            eyeseetee
            wrote on last edited by
            #6

            Well to be honest i used the others guys query because I didnt understand what you mean by t1 :sigh:

            The answers posted by me are suggestions only and cannot be used in anyway against me.

            B 1 Reply Last reply
            0
            • E eyeseetee

              Well to be honest i used the others guys query because I didnt understand what you mean by t1 :sigh:

              The answers posted by me are suggestions only and cannot be used in anyway against me.

              B Offline
              B Offline
              Blue_Boy
              wrote on last edited by
              #7

              Anyway :) ,if you want post here result which u get from query and post result which you want.


              I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

              E 1 Reply Last reply
              0
              • B Blue_Boy

                Anyway :) ,if you want post here result which u get from query and post result which you want.


                I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

                E Offline
                E Offline
                eyeseetee
                wrote on last edited by
                #8

                It doesnt work, it just shows errors in the sql like incorrect syntax near '1' thanks anyway!

                The answers posted by me are suggestions only and cannot be used in anyway against me.

                B 1 Reply Last reply
                0
                • E eyeseetee

                  It doesnt work, it just shows errors in the sql like incorrect syntax near '1' thanks anyway!

                  The answers posted by me are suggestions only and cannot be used in anyway against me.

                  B Offline
                  B Offline
                  Blue_Boy
                  wrote on last edited by
                  #9

                  .netman wrote:

                  thanks anyway!

                  No problem,it would be my pleasure if I could help you.


                  I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

                  A 1 Reply Last reply
                  0
                  • B Blue_Boy

                    .netman wrote:

                    thanks anyway!

                    No problem,it would be my pleasure if I could help you.


                    I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

                    A Offline
                    A Offline
                    AprNgp
                    wrote on last edited by
                    #10

                    @ Blue_Boy i think in the query u provided, something like, SELECT * FROM table AS t1 is missing ....

                    Apurv

                    B 1 Reply Last reply
                    0
                    • A AprNgp

                      @ Blue_Boy i think in the query u provided, something like, SELECT * FROM table AS t1 is missing ....

                      Apurv

                      B Offline
                      B Offline
                      Blue_Boy
                      wrote on last edited by
                      #11

                      I have already specify table2 as t1 on my first post for this question.


                      I Love T-SQL "Don't torture yourself,let the life to do it for you." If my post helps you kindly save my time by voting my post.

                      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