1

Possible Duplicate:
Cast integer and concatenate to varchar in TSQL

How do you call a stored procedure using named parameters that have more complex values. Here is a somewhat concocted example:

EXEC MyStoredProc @Param1='My name is: '+@Name

Or:

EXEC MyStoredProc @Param1=CONCAT('My name is: ',@Name)

I get an error trying to concatenate the literal string 'My name is: ' with the variable @Name. Parentheses do not help the matter any. Is this a limitation of T-SQL (i.e., when named parameters are used, the expression after the equal sign must be a single literal or variable)?

Thanks

Community
  • 1
  • 1
Michael Goldshteyn
  • 71,784
  • 24
  • 131
  • 181

1 Answers1

5

One way

declare @Var1 varchar(50)
select @Var1 = 'My name is: '+@Name

EXEC MyStoredProc @Param1=@Var1

The same is true with functions as well

you can't do this

EXEC MyStoredProc @Param1=getdate()

you need to do

declare @Var1 datetime
select @Var1 = getdate()

EXEC MyStoredProc @Param1=@Var1
SQLMenace
  • 132,095
  • 25
  • 206
  • 225