What would be an acceptable format for a string to pass to a parameter @StateF in the following Stored Procedure ?
the last If statement is as follows:
If @StateF Is Not Null
BEGIN
SET @SQL = @SQL + ' AND C.State In ' + @StateF
END
I tried the following string but I wasn't successful.
My application builds a concatenated string named strFallInst and let's say it currently has the following value:
strFallInSt is 'AL','AZ'
I then reformatted the string to pass to the parameter @StateF as follows
single qoutes) Chr$(39)
strStateF = Chr$(39) + "(" + strFallInSt + ")" + Chr$(39)
I also tried surrounding the + "(" + strFallInSt + with Chr$(34) (double quotes) but it didn't work either.
strStateF is passed to the Stored Procedure via the following statement in my application:
.Parameters.Append .CreateParameter("StateF", adVarChar, adParamInput, 200, strStateF)
The stored procedure is as follows ( I stripped out part of the Stored Procedure to show just the part that isn't working, namely the @StateF parameter:
CREATE PROCEDURE dbo.procFAllStates
@RptYear int,
@Prop varchar (5),
@Agg varchar (5),
@IRA varchar (5),
@StateF varchar(200),
@SQL varchar(8000)
AS
If exists(select * from dbo.sysobjects where name = 'tblFAllStates' and type = 'U')
Drop table tblFAllStates
Set @SQL =
'SELECT Null As Title, C.FirstName AS [First Name], C.MiddleInitial AS MI, C.LastName AS [Last Name], C.SecondNameFirst AS [Second Name First], C.SecondNameMid AS [Second Name Mid]
INTO tblFAllStates
FROM tblStatesAll
AS S INNER JOIN (tblCustomers AS C INNER JOIN tblProducts AS P ON C.CustomerNumber = P.CustomerNumber) ON S.StateFS = C.State WHERE S.Fall = 1 '
If @StateF Is Not Null
BEGIN
SET @SQL = @SQL + ' AND C.State In ' + @StateF
END
PRINT @SQL
EXEC(@SQL)
GO
the last If statement is as follows:
If @StateF Is Not Null
BEGIN
SET @SQL = @SQL + ' AND C.State In ' + @StateF
END
I tried the following string but I wasn't successful.
My application builds a concatenated string named strFallInst and let's say it currently has the following value:
strFallInSt is 'AL','AZ'
I then reformatted the string to pass to the parameter @StateF as follows
strStateF = Chr$(39) + "(" + strFallInSt + ")" + Chr$(39)
I also tried surrounding the + "(" + strFallInSt + with Chr$(34) (double quotes) but it didn't work either.
strStateF is passed to the Stored Procedure via the following statement in my application:
.Parameters.Append .CreateParameter("StateF", adVarChar, adParamInput, 200, strStateF)
The stored procedure is as follows ( I stripped out part of the Stored Procedure to show just the part that isn't working, namely the @StateF parameter:
CREATE PROCEDURE dbo.procFAllStates
@RptYear int,
@Prop varchar (5),
@Agg varchar (5),
@IRA varchar (5),
@StateF varchar(200),
@SQL varchar(8000)
AS
If exists(select * from dbo.sysobjects where name = 'tblFAllStates' and type = 'U')
Drop table tblFAllStates
Set @SQL =
'SELECT Null As Title, C.FirstName AS [First Name], C.MiddleInitial AS MI, C.LastName AS [Last Name], C.SecondNameFirst AS [Second Name First], C.SecondNameMid AS [Second Name Mid]
INTO tblFAllStates
FROM tblStatesAll
AS S INNER JOIN (tblCustomers AS C INNER JOIN tblProducts AS P ON C.CustomerNumber = P.CustomerNumber) ON S.StateFS = C.State WHERE S.Fall = 1 '
If @StateF Is Not Null
BEGIN
SET @SQL = @SQL + ' AND C.State In ' + @StateF
END
PRINT @SQL
EXEC(@SQL)
GO