concatenation - Concatenate variable in a query - SQL Server 2008 -


my question basic.

i creating stored procedure , have following variable:

@concatenarclausulawhere 

during execution of procedure, several conditions concatenated in variable inserted after where:

select id table1 indstatus = 'true' , (description '%' + @ string + '%') 

my intention like:

select id table1 indstatus = 'true' , (description '%' + @ string + '%') + @ concatenarclausulawhere 

but, not possible. why?

i using sql server 2008

you need dynamic sql append where clause query. select statement not string. need wary of sql injection here. how validating users entering clause parameter?

declare @sql nvarchar(max) = n'select id dbo.table1    indstatus = ''true'' , (description @string)'   + @concatenarclausulawhere;  exec sp_executesql @sql, n'@string nvarchar(max)', n'%' + @string + '%'; 

Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -