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.
| Author |
Topic |
|
fralo
Posting Yak Master
161 Posts |
Posted - 2008-03-12 : 13:07:21
|
| Hey guys, I 'm coding my very first stored procedure as accessed by a.NET application. My input parameter is a dynamically built string. I need to concatenate to a sql query within the SP. I've tried using '+' as the concat. character but it doesn't work.set ANSI_NULLS ONset QUOTED_IDENTIFIER ONgoALTER procedure [dbo].[tmptable_query] (@condition_cl varchar(100)) as select * from temp_table + @condition_clHelp would be appreciated. Thank you. |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2008-03-12 : 13:26:24
|
| You'll have to provide more info Fralo. Right now your query doen't make sense. Is @condition_cl a term to be searched for? As inSelect * FROM yourTable WHERE someColumn = @condition_clJim |
 |
|
|
fralo
Posting Yak Master
161 Posts |
Posted - 2008-03-12 : 13:29:55
|
| Sorry. The @condition_cl is actually the whole condition itself such as..."where col = 'Smith' order by name" |
 |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
|
|
KenW
Constraint Violating Yak Guru
391 Posts |
Posted - 2008-03-12 : 15:08:11
|
| fralo,You're trying to combine dynamic and static SQL together. You can't do that.Search this site for 'dynamic SQL'. You'll see some info about how to do what you want. |
 |
|
|
fralo
Posting Yak Master
161 Posts |
Posted - 2008-03-12 : 15:10:54
|
| Thanks guys but I got it to work using the following:CREATE procedure [dbo].[tmptable_query] (@condition_cl varchar(100)) asBEGINDECLARE @sSQL varchar(2000)SET @sSQL='select * from temp_table '+@condition_clEXEC (@sSQL)END |
 |
|
|
|
|
|