|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 6:06 AM
Points: 100,
Visits: 273
|
|
Hey,
We're going SQL2012 in a few weeks... does this version support parameterized table names? Currently we use dynamic SQL, it would be great if that wasn't necessary anymore.
For example:
DECLARE @tbl VARCHAR(MAX) = 'EMPLOYEES' SELECT * FROM @tbl
Looked it up on google, but saw no mention this is possible in 2012, so I thought lets ask here...
Thx, Raymond
|
|
|
|
|
SSC-Dedicated
           
Group: General Forum Members
Last Login: Today @ 4:11 PM
Points: 37,741,
Visits: 30,020
|
|
Nope.
To be honest, that's something I strongly recommend against. It's a pain, it's a security hole if you're not incredibly careful and it suggests bad design (you wouldn't write a C# class that could operate on any type of object or struct passed in, why do it in SQL?)
Gail Shaw Microsoft Certified Master: SQL Server 2008, MVP SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability
We walk in the dark places no others will enter We stand on the bridge and no one may pass
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 6:06 AM
Points: 100,
Visits: 273
|
|
Hi,
Thanks for your reply, was afraid this would be the outcome.
The reason I need it is: my users can create a "campaign", and based on what's needed within that specific campaign a table is created. So at any time suddenly a new table can be present that is named dbo.Campaign00001, dbo.Campaign00002 etc.
All through a user-interface, they cannot access SQL directly.
|
|
|
|
|
SSC-Enthusiastic
      
Group: General Forum Members
Last Login: Today @ 1:54 PM
Points: 151,
Visits: 1,039
|
|
| If tables have the same structure use a partitioned view, or bind and unbind table to view, or in SQL 2012 use synonym, all depend on your needs.
|
|
|
|
|
Ten Centuries
      
Group: General Forum Members
Last Login: Saturday, May 18, 2013 6:46 PM
Points: 1,074,
Visits: 1,076
|
|
Raymond van Laake (2/7/2013) Hi,
Thanks for your reply, was afraid this would be the outcome.
The reason I need it is: my users can create a "campaign", and based on what's needed within that specific campaign a table is created. So at any time suddenly a new table can be present that is named dbo.Campaign00001, dbo.Campaign00002 etc.
All through a user-interface, they cannot access SQL directly.
if the database is still in design phase , may be you can getaway with Entity Attribute model ; having the user create the table , I don't think that kind of stuff I would prefer.
~ demonfox ___________________________________________________________________ Wondering what I would do next , when I am done with this one
|
|
|
|