I have a stored procedure where I would like to use substring in the where clause, if possible.
Code:
CREATE PROCEDURE GetJobList
@PlantId char(3)
Select ......
From ......
WHERE (dbo.Source.CompanySourceId = 'PROD' and dbo.Batch.ReportDate >= @DateFrom and dbo.Batch.ReportDate <= @DateTo and (if @PlantId <> ' ' then SUBSTRING(dbo.Job.CompanyJobId, 1,3) = @PlantId))
I get syntax error "Incorrect syntax near 'if, incorrect sysntax near 'then'....