declare
@Kol as cursor
if(len(@to_num)<>0)
begin
if(len(@to_num)<18)
begin
set @payam='error'
return
end
else
begin
if(LTRIM(RTRIM(@from_num)) = LTRIM(RTRIM(@to_num)))
set @StrSQL = 'Mashaghel.Code='' & LTRIM(RTRIM(@to_num)) & '''
else
begin
if (LTRIM(RTRIM(@StrSQL)) = '')
set @StrSQL = 'Mashaghel.Code<='' & LTRIM(RTRIM(to_num)) & '''
else
set @StrSQL = @StrSQL + ' AND Mashaghel.Code<='' & LTRIM(RTRIM(@to_num)) & '''
end
end
end
set @Kol=cursor for SELECT * FROM AvarezMashaghel WHERE am in (SELECT Code FROM Mashaghel Where + @StrSQL+ )
此代碼錯誤說::CONCAT SQL字符串到sql命令
set @Kol=cursor for SELECT * FROM AvarezMashaghel WHERE am in (SELECT Code FROM Mashaghel Where + @StrSQL+ )
An expression of non-boolean type specified in a context where a condition is expected
我如何添加字符串StrSQL
到SQL命令?
錯誤發生在哪條線上?你爲什麼問這個問題6次? – 2014-08-31 12:01:37
http://stackoverflow.com/questions/1045880/using-a-cursor-with-dynamic-sql-in-a-stored-procedure – Laurence 2014-08-31 12:06:16
@ElecticLIama:set @ Kol = cursor for SELECT * FROM AvarezMashaghel WHERE am in( SELECT代碼FROM Mashaghel Where + @ StrSQL +) – ashkufaraz 2014-08-31 12:08:12