Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2002
    Location
    Edinburgh
    Posts
    8

    Unanswered: Create Table Question T-Sql

    Why can't I do this :

    declare @strUserName varchar (255)
    declare @strTableName varchar (255)

    set @strUserName = 'alan'
    set @strTableName = 'Table' + @strUsername


    CREATE TABLE @strTableName(
    [DistinctLifeID] [int] NULL,
    ) ON [PRIMARY]

    Is there a way to pass a variable Name into a create statement for a table in T-SQL

    Cheers

  2. #2
    Join Date
    Apr 2002
    Location
    Germany
    Posts
    32
    Try it with the EXECUTE statement:

    DECLARE @tablename varchar(255)
    EXEC ('CREATE TABLE ' + @tablename + '...')

    peter

  3. #3
    Join Date
    Mar 2002
    Location
    Edinburgh
    Posts
    8
    Thanks Peter

    You are indded the man



Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •