Advertisement

03.03.2008 at 05:34PM PST, ID: 23211463
[x]
Attachment Details

Pass Query results to stored procedure

Asked by crundle in MS SQL Server, SQL Query Syntax, SQL Server 2005

Tags: ms SQL

Have a query that provides one row with 3 columns of data. This data then need to be passed as 3 separate values to a stored procedure.

The stored procedure requires Value1, value2, value3. (example "EXECUTE crosstab2 EMP_View, EMP_Event, EMP_Order") How do break the query results into 3 separate variables?
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
DECLARE @selectfield varchar(8000),@ClientID int, @ListType varchar(100), @Queryval varchar(100)
set @ClientID = 2 
set @ListType  = 'air'
 
set @Queryval =  '('+replace( replace( 
                  (SELECT CASE 
                              WHEN Upper(@ListType) = Upper('CONTAINER') Then '(ShipmentView) as EMP_View,(EventView) as EMP_Event,(field_order)'
                              WHEN Upper(@ListType) = Upper('TRUCK') THEN  '(Roadview) as EMP_View,(RoadEvent) as EMP_Event,(RoadField_order)'
                              WHEN Upper(@ListType) = Upper('Air') THEN 'AirView[AirEvent]null'
                              ELSE  'null  as EMP_View,null,null'
                        End)
,']',') as EMP_Event,(') ,'[',') as EMP_View,(') + ') as EMP_order'
 
EXEC ('SELECT  '+ @Queryval + ' FROM customer_employees where EmployeeID =' + @ClientID)
 
 
 
Results from above code
                  EMP_Event                                              |                  EMP_View                      |   EMP_order
----------------------------------------------------------------------|------------------------------------------------|---------------
*CLIENT_NAME*,*PONumber*,*stAddress2*,*rtAddress2*,*SSLType_of_Move*  |  *27*,*28*,*29*,*30*,*31*,*32*,*33*,*34*,*35*  |     NULL
[+][-]03.03.2008 at 06:00PM PST, ID: 21037645

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]03.03.2008 at 06:38PM PST, ID: 21037792

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]03.03.2008 at 06:42PM PST, ID: 21037825

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MS SQL Server, SQL Query Syntax, SQL Server 2005
Tags: ms SQL
Sign Up Now!
Solution Provided By: bhess1
Participating Experts: 1
Solution Grade: A
 
 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628