Help in T-SQL
Hi I have the following case.i would like a precise and efficient SQL Statement for it.
I have 7 parameters which are used for comparison. I need to run the query with these parameters. which ever is not null should be compared and the null ones should be ignored. AS a result I end with lots of "if' statements as the parameters form a lot of copmbination. Is there any way to cut short the code
ALTER
PROCEDURE [dbo].[JobsDb_Resumes_SelectForMatchingSkills]@sSkill
varchar(50),@iCountryID
int=NULL,@iStateID
int=NULL,@iJobTypeID
int=NULL,@iMinSal
int=NULL,@iMaxSal
intNULL,@iPeriodPosted
intNULLAS
IF
@iCountryID!=NULLAND @iStateID=NULLAND @iJobTypeID=NULLand @iMinSal=NULLand @iMaxSal=Nulland iPeriodPosted=NULLSELECT*FROM [dbo].[JobsDb_Resumes]where targetcountryid=@iCountryIDandresumetext
like('%'+ @sSkill+'%')ORDERBY [postdate]DESCIF
@iCountryID!=NULLAND @iStateID!=NULLAND @iJobTypeID=NULLand @iMinSal=NULLand @iMaxSal=Nulland iPeriodPosted=NULLSELECT*FROM [dbo].[JobsDb_Resumes]where targetcountryid=@iCountryIDANDtargetstateid
=@iStateIDandresumetext
like('%'+ @sSkill+'%')ORDERBY [postdate]DESCIF
@iCountryID!=NULLAND @iStateID!=NULLAND @iJobTypeID!=NULLand @iMinSal=NULLand @iMaxSal=Nulland iPeriodPosted=NULLSELECT*FROM [dbo].[JobsDb_Resumes]where targetcountryid=@iCountryIDANDtargetstateid
=@iStateIDandjobtypeid
=@iJobTypeIDandresumetext
like('%'+ @sSkill+'%')ORDERBY [postdate]DESCIF
@iCountryID!=NULLAND @iStateID!=NULLAND @iJobTypeID!=NULLand @iMinSal!=NULLand @iMaxSal=Nulland iPeriodPosted=NULLSELECT*FROM [dbo].[JobsDb_Resumes]where targetcountryid=@iCountryIDANDtargetstateid
=@iStateIDandjobtypeid
=@iJobTypeIDandminsalary
>= @iminsalandresumetext
like('%'+ @sSkill+'%')ORDERBY [postdate]DESCIF
@iCountryID!=NULLAND @iStateID!=NULLAND @iJobTypeID!=NULLand @iMinSal!=NULLand @iMaxSal!=Nulland iPeriodPosted=NULLSELECT*FROM [dbo].[JobsDb_Resumes]where targetcountryid=@iCountryIDANDtargetstateid
=@iStateIDandjobtypeid
=@iJobTypeIDandminsalary
>= @iminsalandmaxsalary
>= @imaxsalandresumetext
like('%'+ @sSkill+'%')ORDERBY [postdate]DESCIF
@iCountryID!=NULLAND @iStateID!=NULLAND @iJobTypeID!=NULLand @iMinSal!=NULLand @iMaxSal!=Nulland iPeriodPosted=NULLSELECT*FROM [dbo].[JobsDb_Resumes]where targetcountryid=@iCountryIDANDtargetstateid
=@iStateIDandjobtypeid
=@iJobTypeIDandminsalary
>= @iminsalandmaxsalary
>= @imaxsalandresumetext
like('%'+ @sSkill+'%')ORDERBY [postdate]DESCIF
@iCountryID!=NULLAND @iStateID!=NULLAND @iJobTypeID!=NULLand @iMinSal!=NULLand @iMaxSal!=Nulland iPeriodPosted!=NULLSELECT*FROM [dbo].[JobsDb_Resumes]where targetcountryid=@iCountryIDANDtargetstateid
=@iStateIDandjobtypeid
=@iJobTypeIDandminsalary
>= @iminsalandmaxsalary
>= @imaxsalandresumetext
like('%'+ @sSkill+'%')ORDERBY [postdate]DESC
