Shezad Ahmed
asked on
Build a SQL Select statement
Hi Guys
I am trying to build a simple Select statement.
DECLARE @BasicField AS VARCHAR(50)
set @BasicField = 'City'
Select * from dbo.AMGR_Client_Tbl
where @BasicField = 'Slough'
This does not bring any data back.
i thought the select statement would be:
Select * from dbo.AMGR_Client_Tbl
where City = 'Slough'
This brings a number of rows back.
Any help please!!
I am trying to build a simple Select statement.
DECLARE @BasicField AS VARCHAR(50)
set @BasicField = 'City'
Select * from dbo.AMGR_Client_Tbl
where @BasicField = 'Slough'
This does not bring any data back.
i thought the select statement would be:
Select * from dbo.AMGR_Client_Tbl
where City = 'Slough'
This brings a number of rows back.
Any help please!!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks.
Since this answered your question, by the rules on EE, it cannot be a B answer. Please change it to an A.
ASKER
How do I change it.
set @BasicField = 'City'
Select * from dbo.AMGR_Client_Tbl
where @BasicField = 'Slough'
This query would be trying to find rows where 'City'='Slough' which will never return any rows.