SET @SQLScript = 'SELECT b.name
FROM tblBrand b
JOIN tblStore s ON b.PK_BrandID = s.FK_BrandID
JOIN tblCustomReportTemp CT on b.PK_BrandID = CT.BrandID
WHERE b.Active =1 '
if(@reportname is not null)
set @SQLScript = @SQLScript + ' AND CT.ReportName = @reportname'
if(@username is not null)
set @SQLScript = @SQLScript + ' AND CT.UserName = @username'
The above lines throw:
An expression of non-boolean type specified in a context where a condition is expected, near 'Repo'.
SELECT b.name, FROM tblBrand b
this comma should be removed or add new parameter here.. – MarmiK