I am having a problem how to compare form field values to a value in an SQL entry, through a stored procedure.For example, this is the stored procedure:ALTER PROCEDURE [dbo].[vts_spVoterExportCSVData] @SurveyID int, @StartDate datetime, @EndDate datetimeASSELECT SUBSTRING(Q.QuestionText,1,20) as QuestionText,Q.QuestionId, AnswerID,SelectionModeId,AnswerTypeId, SUBSTRING(Q.QuestionText,1,20)+'...'+' | '+ AnswerText as ColumnHeader ,AnswerText,Q.DisplayOrder QuestionDisplayOrder,Q.QuestionId,Q.Alias QuestionAlias,Q.QuestionIdText QuestionIdText,A.DisplayOrder AnswerDisplayOrder,A.AnswerId ,A.AnswerAlias,Q.ParentQuestionid, case when q.parentQuestionId is null then null else (select count(*)+1 from vts_tbquestion q1 where q1.parentquestionid=q.parentquestionid and q1.questionid<q.questionid ) end as roworder, case when q.parentQuestionId is null then null else (select QuestionText from vts_tbquestion q1 where q1.questionid=q.parentquestionid ) end as ParentQuestiontext, case when q.parentQuestionId is null then null else (select QuestionIdText from vts_tbquestion q1 where q1.questionid=q.parentquestionid ) end as ParentQuestionIdtext, case when q.parentQuestionId is null then null else (select ALIAS from vts_tbquestion q1 where q1.questionid=q.parentquestionid ) end as ParentQuestionAliastext,A.AnswerIDText AnswerIdText FROM vts_tbQuestion QINNER JOIN vts_tbAnswer A ON A.QuestionID = Q.QuestionIDWHERE SurveyID = @SurveyID ORDER BY Q.DisplayOrder, Q.QuestionID, A.DisplayOrderSELECT V.VoterID, V.VoteDate, V.StartDate, V.IPSource, V.ContextUserName as username, (SELECT sum(ScorePoint) FROM vts_tbVoter INNER JOIN vts_tbVoterAnswers ON vts_tbVoterAnswers.VoterID = vts_tbVoter.VoterID INNER JOIN vts_tbAnswer ON vts_tbAnswer.AnswerID = vts_tbVoterAnswers.AnswerID WHERE vts_tbVoter.VoterID = V.VoterID) AS Score FROM vts_tbVoter V WHERE V.SurveyID = @SurveyID AND V.Validated <> 0 AND DATEDIFF (d,@startDate,V.VoteDate) >= 0 AND DATEDIFF (d,@endDate,V.VoteDate) <= 0 AND V.VoterID IN (SELECT VoterID FROM vts_tbVoterAnswers WHERE AnswerID='31') ORDER BY V.VoterID DESC SELECT V.VoterID, VA.AnswerID, SectionNumber, VA.AnswerText, AnswerTypeId, SelectionModeId, Q.QuestionId, A.AnswerText AnswerAnswerText, A.DisplayOrder AnswerDisplayOrder,A.AnswerAlias,A.AnswerIDText AnswerIdAliasFROM vts_tbVoterAnswers VAINNER JOIN vts_tbVoter V ON V.VoterID = VA.VoterIDINNER JOIN vts_tbAnswer A ON VA.AnswerId=A.AnswerIdINNER JOIN vts_tbQuestion Q ON A.QuestionId=Q.QuestionIdWHERE V.SurveyID = @SurveyID AND V.Validated <> 0 AND DATEDIFF (d,@startDate,V.VoteDate) >= 0 AND DATEDIFF (d,@endDate,V.VoteDate) <= 0 AND V.VoterID IN (SELECT VoterID FROM vts_tbVoterAnswers WHERE AnswerID='31') ORDER BY V.VoterID DESC
What this does is collect the proper data from four tables: - vts_tbQuestion: Q- vts_tbAnswer: A- vts_tbVoterAnswers: VA- vts_tbVoter: VAnd pushes them for extraction in CSV file. the following line:V.VoterID IN (SELECT VoterID FROM vts_tbVoterAnswers WHERE AnswerID='31')
..actually looks for the VoterID entry in the vts_tbVoterAnswers table where the entry of the AnswerID='31'.What I want to do is have the value of the AnswerID be taken from an asp form field with the ID: ddlSeed. I considered adding an SQL variable: @Seed which should get the value and simply change the above code into: V.VoterID IN (SELECT VoterID FROM vts_tbVoterAnswers WHERE AnswerID=@Seed)But the problem is I dont know how to supply @Seed with a value from the specific form field.Anyone has any idea how to do this?