We help IT Professionals succeed at work.
Get Started

Concatenate results from mutlple sql queries

T Hoecherl
T Hoecherl asked
on
66 Views
Last Modified: 2015-12-23
I have three SQL queries, each of which gives me a result.  What I want is for the results to be concatenated and either inserted in a table that can then be exported to a text file or directly to a text file.  For example, the first two queries and their results are:

Query1:
Select '<V1.0>,"' + substring(@Batch_Num, 7, 2 ) + substring(@Batch_Num, 10, 2) + 'C"'

Result:
<V1.0>,"2301C"

Query2:
Select '*,"' + substring(@Batch_Num, 2, 1) + substring(@Batch_Num, 4, 2) + substring(@Batch_Num, 7, 2 ) + substring(@Batch_Num, 10, 2) + 'c",,"PONUM",,,"' +
                + substring(@Batch_Num, 2, 1) + substring(@Batch_Num, 4, 2) + substring(@Batch_Num, 7, 2 ) + substring(@Batch_Num, 10, 2) + 'c.dat"'

Result:
*,"5112301c",,"PONUM",,,"5112301c.dat"

I want to run the queries together and get this result:
<V1.0>,"2301C"
*,"5112301c",,"PONUM",,,"5112301c.dat"

How can I accomplish this?

T
Comment
Watch Question
CERTIFIED EXPERT
Top Expert 2010
Commented:
This problem has been solved!
Unlock 1 Answer and 11 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE