?
Solved

Use CF to "merge" two SQL Server queries

Posted on 2005-03-02
3
Medium Priority
?
1,159 Views
Last Modified: 2013-12-24
I have two SQL Server queries I'm manipulating in ColdFusion that I really need to be able to manipulate as one query.

If I were running Oracle, INTERSECT in the query would do what I want in a snap, but no such luck.

Any graceful way to do this in ColdFusion? I expect large datasets, so it would need to be pretty efficient. The two queries are as follows. You can see their results columns are exactly the same.

<cfquery name="GetAllMultipleChoiceResponses" datasource="quiz1">
      SELECT RespondentID, QuestionID, OptionValue AS Response
      FROM MultipleChoiceResponses, Respondents, MultipleChoiceOptions
      WHERE MultipleChoiceResponses.RespondentID = Respondents.ID
      AND MultipleChoiceResponses.OptionID = MultipleChoiceOptions.ID
      AND Respondents.SurveyID = #GetSurveyID#
</cfquery>

<cfquery name="GetAllTextResponses" datasource="quiz1">
      SELECT RespondentID, QuestionID, AnswerText AS Response
      FROM TextResponses, Respondents
      WHERE TextResponses.RespondentID = Respondents.ID
      AND Respondents.SurveyID = #GetSurveyID#
</cfquery>

Bonus points (I can do that, right?) for being able to sort the resulting/combined query by RespondentID ASC, QuestionID ASC!
0
Comment
Question by:Sapphireblue
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 8

Accepted Solution

by:
kyle1830 earned 2000 total points
ID: 13443561
use a union
<cfquery name="GetAllMultipleChoiceResponses" datasource="quiz1">
     SELECT RespondentID, QuestionID, OptionValue AS Response
     FROM MultipleChoiceResponses, Respondents, MultipleChoiceOptions
     WHERE MultipleChoiceResponses.RespondentID = Respondents.ID
     AND MultipleChoiceResponses.OptionID = MultipleChoiceOptions.ID
     AND Respondents.SurveyID = #GetSurveyID#
UNION
     SELECT RespondentID, QuestionID, AnswerText AS Response
     FROM TextResponses, Respondents
     WHERE TextResponses.RespondentID = Respondents.ID
     AND Respondents.SurveyID = #GetSurveyID#
</cfquery>

Kyle
0
 
LVL 1

Author Comment

by:Sapphireblue
ID: 13443647
yikes. that's what I was thinking of, not Intersect, which I realize now is a totally different thing.

le sigh. Thank you!
0
 
LVL 8

Expert Comment

by:kyle1830
ID: 13443669
youre welcome,  sometimes another pair of eyes help.

kyle
0

Featured Post

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever sent email via ColdFusion and thought of tracking this mail to capture the exact date and time when the message was opened ?  If yes, then this article is for you ! First we need a table user_email with columns user_id , email , sub…
Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

801 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question