Hi Folks
coming back to a problem I was having a couple of months ago, I wasn't able to solve it then and I was working around it, now I'm back to it.
I'm trying to write an SP that allows me to put in one or more of many different search criteria for changing what comes back in the dataset returned. I have put together the following query based on what I've read from several internet sites and such:
As you can probably tell because I'm asking about this, it isn't working. I get no results back no matter what I put in for criteria. Is there anything I'm doing wrong that I can fix? I'm afraid I really don't understand dynamic SQL yet...
Thanks
Craig
coming back to a problem I was having a couple of months ago, I wasn't able to solve it then and I was working around it, now I'm back to it.
I'm trying to write an SP that allows me to put in one or more of many different search criteria for changing what comes back in the dataset returned. I have put together the following query based on what I've read from several internet sites and such:
Code:
PROCEDURE [dbo].[spSPFillGridPlus]
-- Add the parameters for the stored procedure here
@Par1 varchar(50) = NULL,
@Par2 varchar(50) = NULL,
@Par3 varchar(50) = NULL,
@Par4 varchar(50) = NULL,
@Par5 varchar(50) = NULL,
@Par6 varchar(50) = NULL,
@Par7 varchar(50) = NULL,
@Par8 varchar(50) = NULL
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
SELECT CLIC, IndName, IndCity, IndState, IndRR, ShipRecv, Siding, Commodity, Notes FROM Industry
WHERE Active = 'X'
AND ((@Par1 IS NULL) OR Commodity = @Par1)
AND ((@Par2 IS NULL) OR ShipRecv IN (@Par2, 'B'))
AND ((@Par3 IS NULL) OR CLIC LIKE @Par3)
AND ((@Par4 IS NULL) OR CLIC NOT LIKE @Par4)
AND ((@Par5 IS NULL) OR IndName LIKE @Par5)
AND ((@Par6 IS NULL) OR IndCity LIKE @Par6)
AND ((@Par7 IS NULL) OR IndState LIKE @Par7)
AND ((@Par8 IS NULL) OR IndRR LIKE @Par8)
ORDER BY IndName;
END
As you can probably tell because I'm asking about this, it isn't working. I get no results back no matter what I put in for criteria. Is there anything I'm doing wrong that I can fix? I'm afraid I really don't understand dynamic SQL yet...
Thanks
Craig