I have an ASP page which has several dropdown boxes which allow the user to select multiple items. I have been trying to get the stored procedure to return the filtered recordset but am having trouble with the appropriate use of apostrophies in the string parameters. Also, is my use of the COALESCE function possible when the parameter is a CSV?
Alter Procedure "spMishapCount_Filtered_IN"
(
@AC_Type varchar(100) = NULL,
@Mishap_Type varchar(30) = NULL,
@Mishap_Class varchar(10) = NULL,
@Location varchar(100) = NULL,
@Service varchar(100) = NULL,
@Year varchar(100) = NULL
)
As
Set nocount on
--Insert filtered data into Temp Filter_Table
SELECT MishapID INTO #tblTemp_Filter_Table
FROM tblMishaps
WHERE tblMishaps.Aircraft_FK IN (COALESCE(@AC_Type, tblMishaps.Aircraft_FK)) AND
tblMishaps.Type_FK IN (COALESCE(@Mishap_Type, tblMishaps.Type_FK)) AND
tblMishaps.Class_FK IN (COALESCE(@Mishap_Class, tblMishaps.Class_FK)) AND
tblMishaps.LocationID_FK IN (COALESCE(@Location, tblMishaps.LocationID_FK)) AND
tblMishaps.OrgID_FK IN (COALESCE(@Service, tblMishaps.OrgID_FK)) AND
CAST(Year(DateAdd(month,3,tblMishaps.MishapDate)) AS varchar(100)) IN (COALESCE(@Year, CAST(Year(DateAdd(month,3,tblMishaps.MishapDate)) AS varchar(100)))) AND
NOT(tblMishaps.DatabaseType = 'C')
Alter Procedure "spMishapCount_Filtered_IN"
(
@AC_Type varchar(100) = NULL,
@Mishap_Type varchar(30) = NULL,
@Mishap_Class varchar(10) = NULL,
@Location varchar(100) = NULL,
@Service varchar(100) = NULL,
@Year varchar(100) = NULL
)
As
Set nocount on
--Insert filtered data into Temp Filter_Table
SELECT MishapID INTO #tblTemp_Filter_Table
FROM tblMishaps
WHERE tblMishaps.Aircraft_FK IN (COALESCE(@AC_Type, tblMishaps.Aircraft_FK)) AND
tblMishaps.Type_FK IN (COALESCE(@Mishap_Type, tblMishaps.Type_FK)) AND
tblMishaps.Class_FK IN (COALESCE(@Mishap_Class, tblMishaps.Class_FK)) AND
tblMishaps.LocationID_FK IN (COALESCE(@Location, tblMishaps.LocationID_FK)) AND
tblMishaps.OrgID_FK IN (COALESCE(@Service, tblMishaps.OrgID_FK)) AND
CAST(Year(DateAdd(month,3,tblMishaps.MishapDate)) AS varchar(100)) IN (COALESCE(@Year, CAST(Year(DateAdd(month,3,tblMishaps.MishapDate)) AS varchar(100)))) AND
NOT(tblMishaps.DatabaseType = 'C')