Derived Columns in where clause
-
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
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
-
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
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
-
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
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
-
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
Have you tried
SELECT COL2 FROM TABLE
? You would get the content from that column like:COL2
bbb
yui
hgjkIf this is not what you need, then you need to elaborate more.
"When did ignorance become a point of view" - Dilbert
-
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
-
Have you tried
SELECT COL2 FROM TABLE
? You would get the content from that column like:COL2
bbb
yui
hgjkIf this is not what you need, then you need to elaborate more.
"When did ignorance become a point of view" - Dilbert
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.
-
The following discussion will answer your question : http://www.codeproject.com/Messages/3523731/Sqlparameter.aspx[^]
I don't like my signature at all
Thanks Estys but its dynamic query right. Is there any way to use built in key words like column_Name in where clause
-
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.
Then you need to use dynamic sql as suggested by Estys.
"When did ignorance become a point of view" - Dilbert
-
Thanks Estys but its dynamic query right. Is there any way to use built in key words like column_Name in where clause
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
-
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
Sorry... I couldn't get u?
-
Sorry... I couldn't get u?
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: