Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Help with Stored Proc PLEASE

Author  Topic 

jesus4u
Posting Yak Master

204 Posts

Posted - 2001-12-12 : 11:58:13
I want to dynamically load the last part of my WHERE clause by placing the variable @Wcl in place of the AND (dbo.Sections.SectionID = 13) AND (dbo.CJQDetail.ResponseID >= 76 AND
dbo.CJQDetail.ResponseID <= 78)

WHERE clause like so: Can it be done?


declare @WCl varchar(100)
set @Wcl = 'AND (dbo.CJQDetail.ResponseID >= 76 AND
dbo.CJQDetail.ResponseID <= 78)'

SELECT COUNT(dbo.Response.QuestionID) AS ResponsesFound, dbo.Response.QuestionID, dbo.CJQDetail.CJQID, dbo.Questions.SectionID,
dbo.Sections.SectionName, dbo.Questions.MinResponse, dbo.Sections.FormID, dbo.Sections.AspPageNum, dbo.Questions.QuestionID AS Expr1,
dbo.CJQDetail.ResponseID
FROM dbo.CJQDetail INNER JOIN
dbo.Response ON dbo.CJQDetail.ResponseID = dbo.Response.ResponseID AND dbo.CJQDetail.ResponseID = dbo.Response.ResponseID INNER JOIN
dbo.Questions ON dbo.Response.QuestionID = dbo.Questions.QuestionID INNER JOIN
dbo.Sections ON dbo.Questions.SectionID = dbo.Sections.SectionID
GROUP BY dbo.Response.QuestionID, dbo.CJQDetail.CJQID, dbo.Questions.SectionID, dbo.Sections.SectionName, dbo.Questions.MinResponse,
dbo.Sections.FormID, dbo.Sections.AspPageNum, dbo.Sections.SectionID, dbo.Questions.QuestionID, dbo.CJQDetail.ResponseID
HAVING (dbo.CJQDetail.CJQID = 5) AND (dbo.Sections.FormID = 1) AND (dbo.Sections.SectionID = 13) AND (dbo.CJQDetail.ResponseID >= 76 AND
dbo.CJQDetail.ResponseID <= 78)



LarsG
Constraint Violating Yak Guru

284 Posts

Posted - 2001-12-12 : 12:10:13
You need to use dynamic SQL.

Here is an article to get you started

http://www.sqlteam.com/item.asp?ItemID=4599

Go to Top of Page

Arnold Fribble
Yak-finder General

1961 Posts

Posted - 2001-12-12 : 12:16:43
Typo?

dbo.CJQDetail INNER JOIN
dbo.Response ON dbo.CJQDetail.ResponseID = dbo.Response.ResponseID AND dbo.CJQDetail.ResponseID = dbo.Response.ResponseID



Go to Top of Page
   

- Advertisement -