Author |
Topic |
tanvirasad
Starting Member
10 Posts |
Posted - 2006-11-03 : 04:34:49
|
I have table where I have stored the SQL Statement when I fire the query on that record it shoul run the statement which is stored in that column.e.gINSERT INTO MyTable ('Select MyCol From MySecondTable')When I Run "Select * From MyTable"It Should Run"Select MyCol From MySecondTable"Tanvir Asad |
|
madhuotp
Yak Posting Veteran
78 Posts |
Posted - 2006-11-03 : 05:40:15
|
hi,I think you should explain the scenario....... Here , u r expecting a lot from a single statement..... What i understand is you have to use dynamic sql. sp_executesql kind of stuffMadhu |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-03 : 06:01:20
|
http://www.soommarskog.se/dynamic_sql.htmldeclare @sqlcmd varchar(8000)select @sqlcmd = mycolfrom mytablewhere mypk = 2exec (@sqlcmd)Peter LarssonHelsingborg, Sweden |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-11-03 : 06:46:41
|
why did you store queries in a column?MadhivananFailing to plan is Planning to fail |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-03 : 12:53:45
|
It is not that uncommon. I have to do it too in one of my projects I have made some kind of report generator, where the users can select a number of options. The finished query is saved in clear text, and filed under a user selected named for easy reuse.Peter LarssonHelsingborg, Sweden |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-11-04 : 06:29:17
|
quote: Originally posted by Peso It is not that uncommon. I have to do it too in one of my projects I have made some kind of report generator, where the users can select a number of options. The finished query is saved in clear text, and filed under a user selected named for easy reuse.Peter LarssonHelsingborg, Sweden
I see MadhivananFailing to plan is Planning to fail |
 |
|
tanvirasad
Starting Member
10 Posts |
Posted - 2006-11-06 : 03:55:30
|
Hi,Thanks for the replies but I need some more detailed coz I don't want to change my frontend applicationHere I explain The ScenarioTable1ID Name Addr1 ABC 1-ABC2 DEF 2-XYZ3 GHI 3-DEFTable2ID Address21 Select Addr From Table1 Where ID =12 Select Addr From Table1 Where ID =23 Select Addr From Table1 Where ID =3Now ExecutionWhen I Hit a Query on Table2Select Address2 From Table2 Where ID = 1It Should Return The Address From Table1 By Executing The QueryTanvir Asad |
 |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-11-06 : 04:37:38
|
As I wrote in my previous answer...declare @sqlcmd varchar(8000)select @sqlcmd = address2from table2where id = 2exec (@sqlcmd) Peter LarssonHelsingborg, Sweden |
 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2006-11-06 : 06:29:15
|
oh yeah i didnt check this, while replying to other post.. :-(We also have a report writer where we save the query in the database, but then we normally call everything from the front end. Chiraghttp://chirikworld.blogspot.com/ |
 |
|
|