String concatenation in procedure parameters

sql, sql-server, sql-server-2008, t-sql

Solution

You need to fix your code, sorry. There is no magic that will make this legal:

EXEC dbo.procedure_name @var + 'constant';

Also, STOP using the `sp_` prefix for stored procedures.

Problem

I want to do something like this: ``` declare @var varchar(50) = '2'; exec sp_myprocedure 'first', 'sec ' + @var ``` but I get an error: ``` Incorrect syntax near '+'. ``` Of course I can set variable before exec procedure: ``` set @var = 'sec ' + @var; ``` but I don't want this, because I have many execution in my code and I don't want create million variables.

Original source