DECLARE @ddl varchar(1024) SET @ddl = 'CREATE TABLE dbo.zobj' + @objname + ' ( ' + @objname + 'id numeric IDENTITY(1,1), ' + 'zFile varchar(25) )' EXECUTE (@ddl)>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,