Solved

Concatenate SQL statements

Posted on 2008-10-02
2
330 Views
Last Modified: 2013-12-17
I am building a  sql statement through a for loop.  see below.  when it runs I want string selectquery = selectquery + "INTERSECT " + [the next query generated from the for loop]  how do I do this?


string selectquery = "";
for (int q=0, a=1, x=2; q < carList.Count && a < dealerList.Count && x < dealerList.Count; q++, a+=4, x+=4 )
                        {
                           carname = carList[q].ToString();
		         carprice = dealerList[a].ToString();
		         location = dealerList[x].ToString();
 
 string selectquery = query "SELECT car_name FROM names n, price p, dealer d where name =" + carname + "AND price =" + carprice + "AND dealer =" + location + ";

Open in new window

0
Comment
Question by:MichelleLacy
[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 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 22622844
something like this:
string selectquery = ""; 
for (int q=0, a=1, x=2; q < carList.Count && a < dealerList.Count && x < dealerList.Count; q++, a+=4, x+=4 )
{
  carname = carList[q].ToString();
  carprice = dealerList[a].ToString();
  location = dealerList[x].ToString();
 
  selectquery += ( selectquery == "" ? "" : " UNION ALL " ) + "SELECT car_name FROM names n, price p, dealer d where name = '" + carname.Replace("'", "''") + "' AND price =" + carprice + " AND dealer = '" + location.Replace("'", "''") + "' ";

Open in new window

0
 

Author Closing Comment

by:MichelleLacy
ID: 31502324
thanks for the solution.  I used it immedieately.  I apologize for not updating expert exchange sooner.
0

Featured Post

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

696 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