I have a stored proc defines as follows.
PROCEDURE [dbo].[GetSales](@dateFilter nvarchar(50))
AS
BEGIN
SELECT sum(Amount)
FROM Sales
WHERE SalesDate in (' + @dateFilter + ')
group by SalesDate
END
to select data from this table
Id SalesDate Amount
1 Apr-2010 40.25
2 May-2010 12.10
3 Jun-2010 2.50
I used Execute sp command and passed this text 'Mar-2010','Apr-2010'
The call generated this code and retured nothing.
DECLARE @return_value int
EXEC @return_value = [dbo].[GetSales]
@dateFilter = N'''Mar-2010'',''Apr-2010'''
SELECT 'Return Value' = @return_value
But this (call statement X) works
SELECT sum(Amount)
FROM Sales
WHERE SalesDate in ('Mar-2010','Apr-2010')
group by SalesDate
returning
(No column name)
40.25
How can I fromat the parameter filter so the stored proc uses it as statement X above?