Solved

Concatenate SQL statements

Posted on 2008-10-02
2
324 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
2 Comments
 
LVL 142

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, just open a new email message. In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…

864 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

Need Help in Real-Time?

Connect with top rated Experts

24 Experts available now in Live!

Get 1:1 Help Now