Dale Fye
asked on
convert date variable to text for use in EXEC statement
I'm trying to pass a variable to a stored procedure and return a recordset from the SP. I started with:
Declare @FromDate as Date
Set @FromDate = '2015-07-01'
EXEC df_MyStoredProcedure @FromDate
Which works just fine. But the stored procedure returns a recordset, which I want to stuff into a temporary table, so I migrated to:
CREATE Table #MergeTemp(
[MergeAction] [nvarchar] (10) not null,
[RecCount] [int] not null
)
GO
Declare @FromDate as Date
Set @FromDate = '2015-07-01'
INSERT INTO #MergeTemp EXEC('exec df_MyStoredProcedure @FromDate')
But this obviously doesn't work, because @FromDate is no longer considered a value. How do I modify this EXEC statement to pass the actual date value to the EXEC command?
Declare @FromDate as Date
Set @FromDate = '2015-07-01'
EXEC df_MyStoredProcedure @FromDate
Which works just fine. But the stored procedure returns a recordset, which I want to stuff into a temporary table, so I migrated to:
CREATE Table #MergeTemp(
[MergeAction] [nvarchar] (10) not null,
[RecCount] [int] not null
)
GO
Declare @FromDate as Date
Set @FromDate = '2015-07-01'
INSERT INTO #MergeTemp EXEC('exec df_MyStoredProcedure @FromDate')
But this obviously doesn't work, because @FromDate is no longer considered a value. How do I modify this EXEC statement to pass the actual date value to the EXEC command?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
The above comment has been updated a couple of times after original submission.
ASKER
Jim,
Thanks for the prompt reply. First solution worked great, but good to know the second as well.
Dale
Thanks for the prompt reply. First solution worked great, but good to know the second as well.
Dale
Thanks for the grade Dale. Good luck with your project. -Jim