SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Parameterized table names?


Parameterized table names?

Author
Message
Raymond van Laake
Raymond van Laake
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1027 Visits: 390
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
GilaMonster
GilaMonster
SSC Guru
SSC Guru (233K reputation)SSC Guru (233K reputation)SSC Guru (233K reputation)SSC Guru (233K reputation)SSC Guru (233K reputation)SSC Guru (233K reputation)SSC Guru (233K reputation)SSC Guru (233K reputation)

Group: General Forum Members
Points: 233345 Visits: 46361
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, MVP, M.Sc (Comp Sci)
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


Raymond van Laake
Raymond van Laake
Ten Centuries
Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)Ten Centuries (1K reputation)

Group: General Forum Members
Points: 1027 Visits: 390
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.
e4d4
e4d4
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1227 Visits: 2399
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.
demonfox
demonfox
SSCrazy
SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)SSCrazy (2.2K reputation)

Group: General Forum Members
Points: 2197 Visits: 1192
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 Ermm
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search