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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Variables in SQL 2005

Author  Topic 

kohlhaas77
Starting Member

25 Posts

Posted - 2008-12-12 : 14:18:25
I want to understand the basics of creating variables. Here is the scenario...I want to create a table variable so that I can plug in the name of any talbe and it will be used wherever that variable is used.

Set @table = 'My_Table_Name'

Select *
From @table

Says I need to declare the scalar and table variable.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-12 : 14:20:43
This is a terrible idea. It is lazy coding and is bad for security and performance reasons.

Why do you want to design a system like this?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

kohlhaas77
Starting Member

25 Posts

Posted - 2008-12-12 : 14:27:30
Um, because my boss rcommended it. lol I guess you are not fond of the idea.
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-12-12 : 14:48:00
Explain to him that it'll require dynamic sql and that dynamic sql is bad for security and performance reasons. Your boss apparently doesn't have much experience with SQL Server, so make sure to provide him with supporting documentation. This question gets asked at least once a week, so you should be able to find our unhappy answers by searching.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -