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. Derived Columns in where clause

Derived Columns in where clause

Scheduled Pinned Locked Moved Database
databasequestion
14 Posts 6 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.
  • S SatyaKeerthi15

    I Have Table with columns as 1,2,3,4,5 I need to write query like SELECT * FROM Table where columnName = 2. How can I specify column header in where clause

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

    Hope this will help you SELECT * FROM information_schema.columns WHERE COLUMN_NAME='YourColumnName'


    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. www.aktualiteti.com

    S 1 Reply Last reply
    0
    • B Blue_Boy

      Hope this will help you SELECT * FROM information_schema.columns WHERE COLUMN_NAME='YourColumnName'


      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. www.aktualiteti.com

      S Offline
      S Offline
      SatyaKeerthi15
      wrote on last edited by
      #3

      It gives column details but not data for that column in specified table.

      1 Reply Last reply
      0
      • S SatyaKeerthi15

        I Have Table with columns as 1,2,3,4,5 I need to write query like SELECT * FROM Table where columnName = 2. How can I specify column header in where clause

        J Offline
        J Offline
        Jorgen Andersson
        wrote on last edited by
        #4

        You don't specify the column in the where clause, you do it in the select clause as:

        SELECT <COLUMNNAME>
        FROM <TABLE>;

        "When did ignorance become a point of view" - Dilbert

        J S 2 Replies Last reply
        0
        • J Jorgen Andersson

          You don't specify the column in the where clause, you do it in the select clause as:

          SELECT <COLUMNNAME>
          FROM <TABLE>;

          "When did ignorance become a point of view" - Dilbert

          J Offline
          J Offline
          Jorgen Andersson
          wrote on last edited by
          #5

          Forgot to say, in SQLServer you can put squarebrackets [] around stupid columnnames as a temporary fix.

          "When did ignorance become a point of view" - Dilbert

          1 Reply Last reply
          0
          • J Jorgen Andersson

            You don't specify the column in the where clause, you do it in the select clause as:

            SELECT <COLUMNNAME>
            FROM <TABLE>;

            "When did ignorance become a point of view" - Dilbert

            S Offline
            S Offline
            SatyaKeerthi15
            wrote on last edited by
            #6

            Andersson, did u understand what I meant. I have Table like Srno col1 col2 col3 1 aaaa bbb vvv 2 hjgj yui jhk 3 hkjdf hgjk jkjlk I need to get data for specified column. suppose i sent parameter col2 then bbb,yui,hgjk col3 then vvv,jhk,jkjlk

            J 1 Reply Last reply
            0
            • S SatyaKeerthi15

              Andersson, did u understand what I meant. I have Table like Srno col1 col2 col3 1 aaaa bbb vvv 2 hjgj yui jhk 3 hkjdf hgjk jkjlk I need to get data for specified column. suppose i sent parameter col2 then bbb,yui,hgjk col3 then vvv,jhk,jkjlk

              J Offline
              J Offline
              Jorgen Andersson
              wrote on last edited by
              #7

              Have you tried SELECT COL2 FROM TABLE? You would get the content from that column like:

              COL2
              bbb
              yui
              hgjk

              If this is not what you need, then you need to elaborate more.

              "When did ignorance become a point of view" - Dilbert

              S 1 Reply Last reply
              0
              • S SatyaKeerthi15

                I Have Table with columns as 1,2,3,4,5 I need to write query like SELECT * FROM Table where columnName = 2. How can I specify column header in where clause

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

                The following discussion will answer your question : http://www.codeproject.com/Messages/3523731/Sqlparameter.aspx[^]

                I don't like my signature at all

                S 1 Reply Last reply
                0
                • J Jorgen Andersson

                  Have you tried SELECT COL2 FROM TABLE? You would get the content from that column like:

                  COL2
                  bbb
                  yui
                  hgjk

                  If this is not what you need, then you need to elaborate more.

                  "When did ignorance become a point of view" - Dilbert

                  S Offline
                  S Offline
                  SatyaKeerthi15
                  wrote on last edited by
                  #9

                  Andersson 'SELECT COL2 FROM TABLE' this is basic select query if i know the column name. In my case I don't the column names in table. so if table have column name with col2 then return result otherwise nothing.

                  J 1 Reply Last reply
                  0
                  • E Estys

                    The following discussion will answer your question : http://www.codeproject.com/Messages/3523731/Sqlparameter.aspx[^]

                    I don't like my signature at all

                    S Offline
                    S Offline
                    SatyaKeerthi15
                    wrote on last edited by
                    #10

                    Thanks Estys but its dynamic query right. Is there any way to use built in key words like column_Name in where clause

                    L 1 Reply Last reply
                    0
                    • S SatyaKeerthi15

                      Andersson 'SELECT COL2 FROM TABLE' this is basic select query if i know the column name. In my case I don't the column names in table. so if table have column name with col2 then return result otherwise nothing.

                      J Offline
                      J Offline
                      Jorgen Andersson
                      wrote on last edited by
                      #11

                      Then you need to use dynamic sql as suggested by Estys.

                      "When did ignorance become a point of view" - Dilbert

                      1 Reply Last reply
                      0
                      • S SatyaKeerthi15

                        Thanks Estys but its dynamic query right. Is there any way to use built in key words like column_Name in where clause

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

                        a WHERE clause determines which rows are being returned. :)

                        Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                        Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                        modified on Thursday, July 29, 2010 7:10 AM

                        S 1 Reply Last reply
                        0
                        • L Luc Pattyn

                          a WHERE clause determines which rows are being returned. :)

                          Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum

                          Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.

                          modified on Thursday, July 29, 2010 7:10 AM

                          S Offline
                          S Offline
                          SatyaKeerthi15
                          wrote on last edited by
                          #13

                          Sorry... I couldn't get u?

                          L 1 Reply Last reply
                          0
                          • S SatyaKeerthi15

                            Sorry... I couldn't get u?

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

                            The WHERE clause isn't used to specify which columns you want to retrieve, but to limit the amount of records returned. It's a filter :) What you want to do can only be done using dynamic SQL. You'll have to know what columns you want to retrieve, or use a wildcard (*) to retrieve them all.

                            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