Home All Groups Group Topic Archive Search About

Table results from Exec - Within a UDF

Author
11 Nov 2005 9:21 PM
adi
Hi all,
   I have a question on how to obtain the results of a exec out of a
UDF/Stored Proc?

Currently I haev a UDF that builds a select statement and executes it
using the
[I wanted to return the Statement itself, but was too big for varchar]

return @sqlStatement

I then tried 'select * into #temp from (exec @sqlStatement) -- didn't
work.

why am I doing this? - I want to use the result of this query in
another query that I have in a stored proc. Any ideas will be helpful.

thanks

Author
11 Nov 2005 9:30 PM
adi
If I confused you all, here is the question in an easy form:

How do I read the contents of a "exec @mySqlQuery"  into a temp table?
Author
11 Nov 2005 10:05 PM
Abhishek Pandey
try
insert into #sometable exec('some query')

Make sure you define the schema of the temp table before doing it (its an
"insert into" thing and not "select into insert")

hope this helps. otherwise post your query and some would be able to give
you a suggesstion.

and ya you can do the above thing to store the ouput of a sproc into a temp
table as well.

Do let me know if this solves your problem

Abhishek

Show quote
"adi" wrote:

> If I confused you all, here is the question in an easy form:
>
> How do I read the contents of a "exec @mySqlQuery"  into a temp table?
>
>
Author
11 Nov 2005 10:15 PM
adi
Right, UDF did not work but I palced this stuff in a Stored Proc and it
looks good.


CREATE TABLE ##tempTable (
    id varchar(9), field_id varchar(50), value varchar(8000))

    insert ##tempTable exec(@tempSql)    

thank you!
Author
11 Nov 2005 10:46 PM
ML
Sorry, this won't work inside a function.


ML

AddThis Social Bookmark Button