Hi thereI have a query that is working for the last few months:select qst.ParentQuestionID, qst.questioncode, qst.QuestionName, qst.SurveyID, ans.UserID, case when substring(qst.questioncode,1,2) in (select substring(q.questioncode, 4,2) from questions q join answers ans1 on ans1.questionid = q.questionid where q.isActive = 1 and q.questioncode like '00%' and q.surveyid = 30 and ans1.Answer = '0' and ans1.UserID = ans.UserID) then 0 else qo.QuestionOptionDesc end as QuestionOptionDescfrom questions qst left join Answers ans on ans.QuestionID = qst.QuestionID left join questionoptions qo on qo.QuestionOptionID = ans.Answer left join Users us on us.UserID = ans.UserIDwhere qst.parentQuestionID in (select questionID from questions where hasmatrix = 1) and us.ClientID = 25 and qst.SurveyID = 30 order by us.Firstname, qst.DisplayOrder
Now I get error saying that Msg 8114, Level 16, State 5, Line 1Error converting data type varchar to bigint.So I trace this and I couldn't work it this and till I accidently putting additional filter "and us.UserID IN (SELECT UserID FROM Users WHERE ClientID = 25)" so become like this:select qst.ParentQuestionID, qst.questioncode, qst.QuestionName, qst.SurveyID, ans.UserID, case when substring(qst.questioncode,1,2) in (select substring(q.questioncode, 4,2) from questions q join answers ans1 on ans1.questionid = q.questionid where q.isActive = 1 and q.questioncode like '00%' and q.surveyid = 30 and ans1.Answer = '0' and ans1.UserID = ans.UserID) then 0 else qo.QuestionOptionDesc end as QuestionOptionDescfrom questions qst left join Answers ans on ans.QuestionID = qst.QuestionID left join questionoptions qo on qo.QuestionOptionID = ans.Answer left join Users us on us.UserID = ans.UserIDwhere qst.parentQuestionID in (select questionID from questions where hasmatrix = 1) and us.ClientID = 25 and qst.SurveyID = 30 and us.UserID IN (SELECT UserID FROM Users WHERE ClientID = 25)order by us.Firstname, qst.DisplayOrder
Can someone explain about this?!?! Cause the us.ClientID = 25 is actually similar to us.UserID IN (SELECT UserID FROM Users WHERE ClientID = 25) in this context ?!!?!I know it's working now BUT why ?!?! Why suddenly today the previous query is not working ?!?!!