December 10, 2004 at 5:13 am
Hi,
I am using sql server 2000.
I need to execute a query present in a column and return as a table so that it can be used in another sql statement.
Can any one help me?
Regards,
Dinesh.
December 10, 2004 at 5:26 am
try researching User-defined function. You can use these in-line to retrieve data. There is pretty decent info in BOL
Good Hunting!
AJ Ahrens
webmaster@kritter.net
December 10, 2004 at 5:28 am
keep in mind that that is dynamic sql ! :ermm
http://www.sommarskog.se/dynamic_sql.html 
if you know the structure, you could create a temp object (#tmptbl) and then :
create #tmptbl (....)
insert into #tmptbl
exec(@yoursql)
now you can use #tmptbl further on.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
December 10, 2004 at 5:38 am
how can i execute a statement in a function?
is it possible execute a sql statement in extended stored procedure.
December 10, 2004 at 5:52 am
I think you really should give a bit more information of what you really try to achieve. Try using pseudocode to explain it.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 10, 2004 at 6:20 am
select col1 from tab1 t1 , tab2 t2 where t1.col2=tab2.col2
in the above statement i need to replace tab2 with out replacing the above statement.
insted of tab2 i need a function or anything else which takes a 'sql statement' and execute the statement so that it returns a table.
December 10, 2004 at 6:44 am
Take a look at the link, alzdba gave above. You will get some ideas how to achieve your result. But please, read it carefully and then decide if you want to go down that road.
--
Frank Kalis
Microsoft SQL Server MVP
Webmaster: http://www.insidesql.org/blogs
My blog: http://www.insidesql.org/blogs/frankkalis/[/url]
December 10, 2004 at 7:08 am
keep in mind that that is dynamic sql !
http://www.sommarskog.se/dynamic_sql.html
If your need is as simple as the select you've provided why not make it fully dynamc !
declare @myDYNsql varchar(1000)
set @myDYNsql = 'select col1 from tab1 t1 inner join (' + @myTablecol +') t2 on t1.col2=tab2.col2'
create table #tmpSet (col1 yourdatatype not null )
insert into #tmpSet
exec (@myDYNsql)
I wouldn't want to support this kind of cr** , because of the dynamic part of your dynamic sql. Who knows what "state of the art" queries will be stuffed into your @myTablcol ?? Check out some articles regarding sql-injection.
If you only have a couple of variations of @myTablecol, don't use dynamic sql, but provide all needed queries.
Johan
Learn to play, play to learn !
Dont drive faster than your guardian angel can fly ...
but keeping both feet on the ground wont get you anywhere :w00t:
- How to post Performance Problems
- How to post data/code to get the best help[/url]
- How to prevent a sore throat after hours of presenting ppt
press F1 for solution, press shift+F1 for urgent solution 😀
Need a bit of Powershell? How about this
Who am I ? Sometimes this is me but most of the time this is me
Viewing 8 posts - 1 through 8 (of 8 total)
You must be logged in to reply to this topic. Login to reply