Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Select query problem can anyone help me? . .

Author  Topic 

Sycopons
Starting Member

4 Posts

Posted - 2012-03-21 : 02:07:35

I have a problem in having query like this .

But there's no effect on it.

@FieldName varchar(20),
@Search varchar(10),

as

SELECT * from tbl_name Where @FieldName Like @Search

xSycopons

stepson
Aged Yak Warrior

545 Posts

Posted - 2012-03-21 : 03:32:34
set @str = ' SELECT * from tbl_name Where ' + @FieldName + ' Like ' + @Search +''''
exec (@str)

I think , this is not the right approach
be carefull about sql injection ,read about it (sql injection)
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2012-03-21 : 04:16:44
take a look at this http://www.sommarskog.se/dynamic_sql.html


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

Sycopons
Starting Member

4 Posts

Posted - 2012-03-24 : 19:58:27
Thank you both for the quick response. .

xSycopons
Go to Top of Page
   

- Advertisement -