CREATE PROCEDURE [dbo].[1122]
@SiteID int,
@JBLID int,
@JBCID int,
@Keywords nvarchar(50)
AS
declare @nsql nvarchar(max);
set @nsql = '
Select
AD.JBAID,
Lower(AD.JBATitle) AS JBATitle,
AD.JBALocation,
AD.JBACategory,
AD.JBAPayRate,
CONVERT(CHAR(11),JBADatePosted,106) AS JBADatePosted,
Lower(left(AD.JBADescription, 300) + ''...'') as JBADescription,
AD.JBAFeaturedJob,
AD.JBAOverWrite,
CL.JBCLID,
CL.JBCLName,
CL.JBCLLogo,
AV.ADViews,
AP.Applications
FROM dbo.JBAdvert AD
left join (SELECT AP.JBAPAdvertID, COUNT(AP.JBAPID) Applications FROM dbo.JBApplication AP GROUP BY AP.JBAPAdvertID) AP on AP.JBAPAdvertID = AD.JBAID
left join (SELECT AV.AdvertID, AV.AdViews ADViews FROM dbo.JBADView AV GROUP BY AV.AdvertID, AV.AdViews) AV on AV.AdvertID = AD.JBAID
inner join dbo.JBClient CL on CL.JBCLID = AD.JBAClientID
WHERE JBASiteID = @SiteID
AND AD.JBALocation IN (Select JBLocation from JBLocation ' +
case when @JBLID = '0' then '' else
'where (JBLID = ' + str(@JBLID) + ')' end +
')
AND AD.JBACategory IN(Select JBCategoryLabel from JBCategories ' +
case when @JBCID = '0' then '' else
'where (JBCID = ' + str(@JBCID) + ')' end +
') ' +
case when @Keywords = '' then '' else
'AND JBADescription LIKE ''%''+ @Keywords + ''%'' ' end +
'order by JBAID desc';
exec sp_executeSQL @nsql, N'@Keywords nvarchar(50)', @Keywords
GO
|