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 6, 2013 8:33 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 14, 2014 7:39 AM
Points: 111, Visits: 307
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 6, 2013 9:50 AM


SSC-Forever

SSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-ForeverSSC-Forever

Group: General Forum Members
Last Login: Today @ 11:31 AM
Points: 40,177, Visits: 36,578
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 7, 2013 1:00 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Monday, July 14, 2014 7:39 AM
Points: 111, Visits: 307
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 7, 2013 1:12 AM
SSC Veteran

SSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC VeteranSSC Veteran

Group: General Forum Members
Last Login: Yesterday @ 11:22 AM
Points: 223, Visits: 1,731
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: Thursday, July 31, 2014 7:15 PM
Points: 1,129, Visits: 1,163
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