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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-10-29 : 08:26:30
|
| Kalyan writes "I have a SQL Function named sp_dist which accepts 5 variables.Of them one is the table name(@category)This variable is to be used in a query in the function(sp_dist) such as:declare getrecords cursor forselect * from @categorywhere condition1But when i am writing the variable(@category) in place of table name it is not accepting and giving an error.Is there any Other Way?Please Help. Urgent!" |
|
|
mr_mist
Grunnio
1870 Posts |
Posted - 2003-10-29 : 08:35:15
|
| There is another way, but you will need to tell us what you are actually trying to achieve.The reason you get an error is because you would have to use dynamic SQL to use a variable as a table name in the way you show. You can look up dynamic SQL in books online, but you should consider rephrasing your question so that we can rewrite your queries without dynamic SQL, as it is dirty and doth smell.-------Moo. :) |
 |
|
|
AjarnMark
SQL Slashing Gunting Master
3246 Posts |
Posted - 2003-10-31 : 17:10:14
|
quote: Originally posted by mr_mist without dynamic SQL, as it is dirty and doth smell.
Yeah, and that cursor isn't too pretty either.--------------------------------------------------------Visit the SQLTeam Weblogs at [url]http://weblogs.sqlteam.com[/url] |
 |
|
|
|
|
|