C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Communities   Interview   Jobs   Projects   Offshore Development    
Silverlight Tutorials | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Revenue Sharing |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...

New Feature: Community Sites: Create your own .NET community website and start earning from Google AdSense ! It's Free !




sql query


Posted Date: 04 Sep 2008      Total Responses: 1

Posted By: prasanthkumar       Member Level: Gold     Points: 1



am doing a search and am passing

-----------------------------

Exec pr_GetJobs '','China,Iran',1,20,'1,2',7
==============================
CREATE proc pr_GetJobs
(
@JobLocations varchar(100),
@Locations varchar(200),
@cde_MinExperience int,
@cde_maxExperience int,
@JobCategory varchar(100),
-- @Role varchar(100),
@Jobfreshness int
)
as
Begin
set nocount on



declare @sql varchar(8000)

select @sql = 'select distinct j.cde_id as Jobid,j.txt_JobTite,j.txt_JobDescription as Description,
convert(varchar(2),j.cde_MinExperience) + '' To '' + convert(varchar(2),j.cde_maxExperience) + '' Year(s)'' as txt_Experience,
j.txt_Location,j.cde_Vacancy,j.txt_requirements,j.cde_RecruitrId,isnull(r.txt_companyName,''AdminCompany'') as txt_companyname,
convert(varchar(15),dt_PostDate,107) as PostedDate,convert(varchar(15),dt_EndDate,107) as dt_EndDate from t_Job j left join
t_RecruitersProfile r on r.cde_LoginID=j.cde_RecruitrId left join t_job_lnl_Location_JobPosting jl on jl.cde_JobId=j.cde_id
left join t_Job_lnk_Category_jobposting jc on jc.cde_jobId=j.cde_id where j.dt_EndDate>=getdate() and flg_Active=1'
if(@JobLocations != '')
select @sql = @sql + ' and jl.cde_LocId in(' + convert(varchar(100),@JobLocations) + ')'
if(@Locations != '')
select @sql = @sql + ' and j.txt_Location in(' + convert(varchar(100),@Locations) + ')'
if((@cde_MinExperience != 0) and (@cde_maxExperience != 0))
select @sql = @sql + ' and j.cde_MinExperience>=' + convert(varchar(100),@cde_MinExperience) + 'and j.cde_maxExperience<=' + convert(varchar(100),@cde_maxExperience) + ''
if(@JobCategory != '')
select @sql = @sql + ' and jc.cde_catId in(' + convert(varchar(100),@JobCategory) + ')'
if(@Jobfreshness != 0)
select @sql = @sql + ' and j.dt_PostDate>=(getdate()-' + convert(varchar(100),@Jobfreshness) + ')'

select @sql

Exec (@sql)

set nocount off
End



====================

Exec pr_GetJobs '','China,Iran',1,20,'1,2',7
====================

returns error

am passing the value('China,Iran') from a textbox it is allowed to enter nmultiple values seperated by commas

in the above

how can i solve





Responses

Author: mythili d    04 Sep 2008Member Level: SilverRating:     Points: 3

I' m not sure if I understood it correctly the variable @joblocations is getting the value China and the @Location is getting iran if yes isnt this suppose to be in a string in the sql meaning
select * from tblJobs where joblocation='china' for example in that case the tsql that you are using needs '''+@joblocations+'''' and '''+@locations +''' for all that is suppose to go in as string should be in 3 single quotes alternatively I could suggest to print the content of the @sql variable and execute that sql statement that way it would be easier for you to correct these kind of errors.
example
declare @sql nvarchar(1000)
declare @desc varchar(100)
set @desc=('ST-CRCL INTRCHBL HP EAR-GEN ')
set @sql=('select *from tblItem where desc=''' +@desc+'''')
print @sql
exec @sql
Hope that helps
thanks



Post Reply
You must Sign In to post a response.
Next : Sorting in SQL Server Reporting 2000
Previous : search
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers   BizTalk Adaptors    Web Design


Contact Us    Privacy Policy    Terms Of Use