Results 1 to 3 of 3
  1. #1
    Join Date
    Nov 2003
    Posts
    13

    Unanswered: Creating table by variable name

    Hi
    How can i Create a table with variable name
    eg
    suppose variable x=tab1
    I want the table created to be tab1 if x=tab2 then table created shd be tab2.. so how can this be dynamically done(creation of tables as well as stored procs)

    i tried : create table @x .. it doesnt seem to work
    please help
    regards

  2. #2
    Join Date
    Nov 2003
    Location
    Christchurch, New Zealand
    Posts
    1,618
    something like...

    Code:
    CREATE  PROCEDURE [dbo].[usp_CreateTable] 
    
    @tablename varchar(200)
    
    AS
    
    sp_executesql('create table ' + @tablename + ' column definations etc ')

  3. #3
    Join Date
    Nov 2003
    Posts
    13
    thanks.. Ill try this out :-)

Posting Permissions

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