In SQL Server, I have a stored procedure that accepts a date parameter. That date paramater is then passed along to another stored procedure. However, the 2nd stored procedure parameter is named as the first parameter. and then I need to I have 2 different scalar variables:
DECLARE @date date, @sql varchar(100);
SET @date = '2012-07-01';
SELECT @sql = ('EXEC pStoredprocedure @date = '''+@date+'''')
I need the @sql
scalar to contain this text so the stored procedure can call the other stored procedure:
EXEC pStoredprocedure @date = '2012-07-01'
But, when I run my code above, I get this error:
Msg 402, Level 16, State 1, Line 4
The data types varchar and date are incompatible in the add operator.
It's almost like I need to escape the @date
operator. Can this be done?
Side note: Yes, I'm trying to dynamically pass along some variables. I understand the dangers of doing so, but doing it this way is much simpler...