Question : error while executing a stored procedure

CREATE PROCEDURE dbo.usp_RSFurnace_Defects
    @ProdLine varchar(4),
    @EffectiveDate datetime
AS
BEGIN
      SET NOCOUNT ON;

    SELECT *
    FROM dbo.vFurnaceDefects
    WHERE @ProdLine = 'fs'
    AND (dbo.vFurnaceDefects.[Effective Date] BETWEEN CONVERT(DATETIME, @EffectiveDate, 102)
    AND CONVERT(DATETIME, @EffectiveDate, 102))
    OR @ProdLine = 'hv'
    AND (dbo.vFurnaceDefects.[Effective Date] BETWEEN CONVERT(DATETIME, @EffectiveDate, 102)
    AND CONVERT(DATETIME, @EffectiveDate, 102))
    @ProdLine = 'tb'
    AND (dbo.vFurnaceDefects.[Effective Date] BETWEEN CONVERT(DATETIME, @EffectiveDate, 102)
    AND CONVERT(DATETIME, @EffectiveDate, 102));
END
GO
EXECUTE dbo.usp_RSFurnace_Defects;
GO

Msg 102, Level 15, State 1, Procedure usp_RSFurnace_Defects, Line 17
Incorrect syntax near '@ProdLine'.
Msg 201, Level 16, State 4, Procedure usp_RSFurnace_Defects, Line 0
Procedure or function 'usp_RSFurnace_Defects' expects parameter '@ProdLine', which was not supplied.

Below is the View dbo.vFurnaceDefects i created which i am calling in the stored procedure.
SELECT     dbo.op_hist.[Effective Date], dbo.op_hist.Employee, dbo.op_hist.[Work Order], dbo.op_hist.Operation, dbo.op_hist.[Qty Completed],
                      dbo.op_hist.[Qty Reject], dbo.op_hist.[Work Center], dbo.op_hist.ID, dbo.op_hist.[Item Number], dbo.op_hist.Shift, dbo.op_hist.Department,
                      dbo.op_hist.Machine, dbo.op_hist.Site, dbo.xxpt_mstr.Dimension1, dbo.pt_mstr.Description1, dbo.pt_mstr.[Prod Line], dbo.op_hist.[Reject Reason],
                      dbo.xxpt_mstr.[Alternate UM Conversion]
FROM         dbo.op_hist INNER JOIN
                      dbo.pt_mstr ON dbo.op_hist.[Item Number] = dbo.pt_mstr.[Item Number] INNER JOIN
                      dbo.xxpt_mstr ON dbo.op_hist.[Item Number] = dbo.xxpt_mstr.[Item Number]

Answer : error while executing a stored procedure

You can simplify it like this:

1:
2:
3:
4:
5:
SELECT *
    FROM dbo.vFurnaceDefects
    WHERE 
	@ProdLine in ('fs', 'hv', 'tb') AND 
	(dbo.vFurnaceDefects.[Effective Date] BETWEEN CONVERT(DATETIME, @EffectiveDate, 102) AND CONVERT(DATETIME, @EffectiveDate, 102));
Random Solutions  
 
programming4us programming4us