Link to home
Start Free TrialLog in
Avatar of Shezad Ahmed
Shezad AhmedFlag for United Kingdom of Great Britain and Northern Ireland

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!!
Avatar of DanielWillmott
DanielWillmott
Flag of United States of America image

DECLARE @BasicField AS VARCHAR(50)
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.


ASKER CERTIFIED SOLUTION
Avatar of chapmandew
chapmandew
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Shezad Ahmed

ASKER

Thanks.
Since this answered your question, by the rules on EE, it cannot be a B answer. Please change it to an A.
How do I change it.