答案 0 :(得分:3)
你得到的错误是你的选择是在同时吐出resutls的同时更新变量。 按如下方式拆分查询:
ALTER PROC [Admin].[sp_Ques]
(
@QuesID bigint
)
AS
BEGIN
DECLARE @Lang int -- ERROR HERE
IF @QuesID = 0
SET @QuesID =NULL
SELECT TOP 1 @Lang=FQ.AdminLanguageID
FROM Admin.Ques FQ
LEFT OUTER JOIN Admin.QuesTypes FQT ON FQT.QuesTypeID=FQ.QuesTypeID
WHERE FQ.QuesID = Coalesce(@QuesID,QuesID)
SELECT TOP 1 FQ.QuesID, FQ.Ques,QuesAns as QuesAns,FQ.QuesAns[Answers], FQT.QuesType ,FQ.QuesTypeID, FQ.QuesParentID, FQ.Active,FQ.AdminLanguageID
FROM Admin.Ques FQ
LEFT OUTER JOIN Admin.QuesTypes FQT ON FQT.QuesTypeID=FQ.QuesTypeID
WHERE FQ.QuesID = Coalesce(@QuesID,QuesID)
SELECT TelerikLanguage FROM Admin.Language
WHERE AdminLanguageID=@Lang
END
答案 1 :(得分:0)
更改
SELECT TOP 1 FQ.QuesID, FQ.Ques,QuesAns as QuesAns,FQ.QuesAns[Answers], FQT.QuesType ,FQ.QuesTypeID, FQ.QuesParentID, FQ.Active,FQ.AdminLanguageID,@Lang=FQ.AdminLanguageID
FROM Admin.Ques FQ
LEFT OUTER JOIN Admin.QuesTypes FQT ON FQT.QuesTypeID=FQ.QuesTypeID
WHERE FQ.QuesID = Coalesce(@QuesID,QuesID)
要
SELECT TOP 1 @Lang=FQ.AdminLanguageID
FROM Admin.Ques FQ
LEFT OUTER JOIN Admin.QuesTypes FQT ON FQT.QuesTypeID=FQ.QuesTypeID
WHERE FQ.QuesID = Coalesce(@QuesID,QuesID)
当您为select中的变量赋值时,选择列表中的所有项都必须为变量赋值。不只是其中一些。
答案 2 :(得分:0)
错误信息非常清楚 - 您无法在同一查询中组合变量赋值和普通结果集检索。
SELECT TOP 1 FQ.QuesID,
FQ.Ques,
QuesAns as QuesAns,
FQ.QuesAns[Answers],
FQT.QuesType ,
FQ.QuesTypeID,
FQ.QuesParentID,
FQ.Active,
FQ.AdminLanguageID,
@Lang=FQ.AdminLanguageID <---- this is the problem
拆分查询,一切都应该没问题。