Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Parameterized table names? Expand / Collapse
Author
Message
Posted Wednesday, February 06, 2013 8:33 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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
Post #1416547
Posted Wednesday, February 06, 2013 9:50 AM


SSC-Dedicated

SSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-DedicatedSSC-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

Post #1416610
Posted Thursday, February 07, 2013 1:00 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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.
Post #1416843
Posted Thursday, February 07, 2013 1:12 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-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.
Post #1416851
Posted Monday, February 11, 2013 1:24 AM
Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen 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
Post #1418245
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse