Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Creating a table with a dynamic name.
Message
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Stored procedures, Triggers, UDFs
Titre:
Creating a table with a dynamic name.
Divers
Thread ID:
00725229
Message ID:
00725229
Vues:
32
How can you create a table name and field name dynamically? Given the following code I create a table named @zobjectname rather than what @zobjectname evaluates to. Additionally I the field name is literally @objname + 'id' with the plus sign and the single quotes.
CREATE PROCEDURE dbo.CreateNewObj 
		@objName as char(255) = NULL -- If we pass 'FRED'
AS
-- Snipped validation code  

   declare @zobjectname as char (50)
   set @zobjectname = 'dbo.zobj' + @objname -- this would be 'zobjFRED'

CREATE TABLE @zobjectname 
(
	@objname + 'id' numeric IDENTITY(1,1),
	zFile varchar(25) 
)

-- Snipped more
Thanks in advance,
~Joe Johnston USA

"If ye love wealth better than liberty, the tranquility of servitude better than the animated contest of freedom, go home from us in peace. We ask not your counsel or arms. Crouch down and lick the hands which feed you. May your chains set lightly upon you, and may posterity forget that ye were our countrymen."
~Samuel Adams

Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform