Solved

Concatenate SQL statements

Posted on 2008-10-02
2
327 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

776 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