我有這個存儲過程:演員表中的SQL查詢/ INT列表存儲過程
exec SearchResume @KeywordSearch=N'', @GreaterThanDate='2013-09-22 00:00:00',
@CityIDs=N'0,56,31,271,117,327,3,328,228',
@ProvinceIDs=N'0,1,12,13',
@CountryIDs=N'1',
@IndustryIDs=N'0,2,3,4,38,113,114,115,116,117'
沒有返回任何結果,因爲ID在nvarchar的,但實際值是整數。
現在,當我測試用我能夠得到的結果int類型的手動列表實際SP,這是例子:
SELECT DISTINCT
UserID,
ResumeID,
CASE a.Confidential WHEN 1 THEN 'Confidential' ELSE LastName + ',' + FirstName END as 'Name',
a.Description 'ResumeTitle',
CurrentTitle,
ModifiedDate,
CASE ISNULL(b.SalaryRangeID, '0') WHEN '0' THEN CAST(SalarySpecific as nvarchar(8)) ELSE c.Description END 'Salary',
h.Description 'Relocate',
i.Description + '-' + j.Description + '-' + k.Description 'Location'
FROM dbo.Resume a JOIN dbo.Candidate b ON a.CandidateID = b.CandidateID
LEFT OUTER JOIN SalaryRange c ON b.SalaryRangeID = c.SalaryRangeID
JOIN EducationLevel e ON b.EducationLevelID = e.EducationLevelID
JOIN CareerLevel f ON b.CareerLevelID = f.CareerLevelID
JOIN JobType g ON b.JobTypeID = g.JobTypeID
JOIN WillingToRelocate h ON b.WillingToRelocateID = h.WillingToRelocateID
JOIN City i ON b.CityID = i.CityID
JOIN StateProvince j ON j.StateProvinceID = b.StateProvinceID
JOIN Country k ON k.CountryID = b.CountryID
WHERE (b.CityID IN (0,56,31,125,229,5,219,8,228))
AND (b.StateProvinceID IN (0,1,13))
AND (b.CountryID IN (1))
AND (b.IndustryPreferenceID IN (0,2,3,4,5,6,115,116,117))
我想知道我能做些什麼發送int值列表,而不是nvarchar值列表,因爲您可以看到查詢無法正常工作。
由於提前,Laziale
UPDATE:
原來SP:
ALTER PROCEDURE [dbo].[SearchResume]
@KeywordSearch nvarchar(500),
@GreaterThanDate datetime,
@CityIDs nvarchar(500),
@ProvinceIDs nvarchar(500),
@CountryIDs nvarchar(500),
@IndustryIDs nvarchar(500)
AS
BEGIN
DECLARE @sql as nvarchar(4000)
SET @sql = 'SELECT DISTINCT
UserID,
ResumeID,
CASE a.Confidential WHEN 1 THEN ''Confidential'' ELSE LastName + '','' + FirstName END as ''Name'',
a.Description ''ResumeTitle'',
CurrentTitle,
ModifiedDate,
CurrentEmployerName,
PersonalDescription,
CareerObjectives,
CASE ISNULL(b.SalaryRangeID, ''0'') WHEN ''0'' THEN CAST(SalarySpecific as nvarchar(8)) ELSE c.Description END ''Salary'',
e.Description ''EducationLevel'',
f.Description ''CareerLevel'',
g.Description ''JobType'',
h.Description ''Relocate'',
i.Description + ''-'' + j.Description + ''-'' + k.Description ''Location''
FROM dbo.Resume a JOIN dbo.Candidate b ON a.CandidateID = b.CandidateID
LEFT OUTER JOIN SalaryRange c ON b.SalaryRangeID = c.SalaryRangeID
JOIN EducationLevel e ON b.EducationLevelID = e.EducationLevelID
JOIN CareerLevel f ON b.CareerLevelID = f.CareerLevelID
JOIN JobType g ON b.JobTypeID = g.JobTypeID
JOIN WillingToRelocate h ON b.WillingToRelocateID = h.WillingToRelocateID
JOIN City i ON b.CityID = i.CityID
JOIN StateProvince j ON j.StateProvinceID = b.StateProvinceID
JOIN Country k ON k.CountryID = b.CountryID
WHERE ((ModifiedDate > ''' + CAST(@GreaterThanDate as nvarchar(55)) + ''')
'
IF (LEN(@CityIDs) >0)
BEGIN
SET @sql = @sql + 'AND (b.CityID IN (' + @CityIDs + '))'
END
IF (LEN(@ProvinceIDs) >0)
BEGIN
SET @sql = @sql + 'AND (b.StateProvinceID IN (' + @ProvinceIDs + '))'
END
IF (LEN(@CountryIDs) >0)
BEGIN
SET @sql = @sql + 'AND (b.CountryID IN (' + @CountryIDs + '))'
END
IF (LEN(@IndustryIDs) >0)
BEGIN
SET @sql = @sql + 'AND (b.IndustryPreferenceID IN (' + @IndustryIDs + '))'
END
IF (LEN(@KeywordSearch) > 0)
BEGIN
SET @sql = @sql + ' AND (' + @KeywordSearch + ')'
END
SET @sql = @sql + ') ORDER BY ModifiedDate desc'
--select @sql
exec sp_executesql @sql
END
是動態sql的一個選項嗎? – 2014-09-23 10:01:50