|
|
Question : MS sql query results to stored procedure
|
|
Have a query that provides one row with 3 columns of data. This data then need to be passed to a stored procedure. To execute the stored procedure it requires 3 variables "EXECUTE crosstab2 EMP_View,EMP_Event,EMP_Order". How can I get the results to the stored procedure?
Query code;
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
|
Answer : MS sql query results to stored procedure
|
|
Jimhorn, your recommendation caused the following error "Conversion failed when converting the varchar value 'SELECT (AirView) as EMP_View,(AirEvent) as EMP_Event,(null) as EMP_order FROM customer_employees where EmployeeID =' to data type int." any ideas?
The second question is how could I get the results to the stored procedure? EXECUTE crosstab2 Variable from column 1, Variable from column 2 , Variable from column 3
|
|
|
|
|