need help with some stored procedure error [duplicate]
Possible Duplicate:
need help with some stored procedure plz
ERROR:-
A SELECT statement that assigns a value to a variable must not be combined with data-retrieval operations.
The error you are getting is that your select is updating a variable while spitting out the results at the same time. Split up your queries as follows:
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
Change
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)
To
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)
When you are assigning values to variables from a select, all items in the select list must be assigning values to variables. Not just some of them.
The error message is pretty clear - you cannot combine variable assignment and normal result set retrieval in the same query.
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
Split the query and everything should be ok.
精彩评论