07-30-2023, 11:42 PM
I have a stored procedure that returns 80 columns, and 300 rows. I want to write a select that gets 2 of those columns. Something like
SELECT col1, col2 FROM EXEC MyStoredProc 'param1', 'param2'
When I used the above syntax I get the error:
> "Invalid Column Name".
I know the easiest solution would be to change the stored procedure, but I didn't write it, and I can't change it.
Is there any way to do what I want?
- I could make a temp table to put the results in, but because there are 80 columns so I would need to make an 80 column temp table just to get 2 columns. I wanted to avoid tracking down all the columns that are returned.
- I tried using `WITH SprocResults AS ....` as suggested by Mark, but I got 2 errors <BR>
> Incorrect syntax near the keyword 'EXEC'.<BR>Incorrect syntax near ')'.
- I tried declaring a table variable and I got the following error <br>
>Insert Error: Column name or number of supplied values does not match table definition
- If I try <BR>
`SELECT * FROM EXEC MyStoredProc 'param1', 'param2'`<br>
I get the error :<br>
>Incorrect syntax near the keyword 'exec'.
SELECT col1, col2 FROM EXEC MyStoredProc 'param1', 'param2'
When I used the above syntax I get the error:
> "Invalid Column Name".
I know the easiest solution would be to change the stored procedure, but I didn't write it, and I can't change it.
Is there any way to do what I want?
- I could make a temp table to put the results in, but because there are 80 columns so I would need to make an 80 column temp table just to get 2 columns. I wanted to avoid tracking down all the columns that are returned.
- I tried using `WITH SprocResults AS ....` as suggested by Mark, but I got 2 errors <BR>
> Incorrect syntax near the keyword 'EXEC'.<BR>Incorrect syntax near ')'.
- I tried declaring a table variable and I got the following error <br>
>Insert Error: Column name or number of supplied values does not match table definition
- If I try <BR>
`SELECT * FROM EXEC MyStoredProc 'param1', 'param2'`<br>
I get the error :<br>
>Incorrect syntax near the keyword 'exec'.