Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
ranjeetsingh_6
Posting Yak Master
125 Posts |
Posted - 2008-02-27 : 01:11:06
|
| Hi,I am using a simple if staement in a dynamic sql query what is its synax.if @docType ='Doctor'beginselect * from @tablenameendRanjeet Kumar Singh |
|
|
mahesh_bote
Constraint Violating Yak Guru
298 Posts |
Posted - 2008-02-27 : 01:14:17
|
| you r going right. in Dynamic SQL u need to just concatenate the Select statement. e.g.if @docType ='Doctor'begin @strSQL = 'select * from ' + @tablenameendthanks,Mahesh |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2008-02-27 : 01:16:48
|
| the syntax u posted is accurate if tablename was the actual declared name of a table. I believe u are looking forIf @doctype = 'whatever'beginexec('select * from ' + @tablename)end |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2008-02-27 : 01:38:50
|
| Why do you want to pass table name as parameter?Make sure you read this fullywww.sommarskog.se/dynamic_sql.htmlMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|