Professional Web Applications Themes

Create Table Using Passed Variables to SP - Microsoft SQL / MS SQL Server

I am trying to create a table by passing the name of the table to create. Here is a section of the sp. Any help is appreciated. CREATE PROCEDURE [dbo].[sp_CreateMyTable] TableName varchar(255) AS Set QUOTED_Identifier on Declare strName varchar(255) IF (TableName <> '') PRINT 'Table name is ' + TableName --RETURN 1 Set strName=TableName CREATE TABLE [dbo].['TableName'] ([LEV1] [char] (6) COLLATE GO...

  1. #1

    Default Create Table Using Passed Variables to SP

    I am trying to create a table by passing the name of the
    table to create. Here is a section of the sp. Any help is
    appreciated.

    CREATE PROCEDURE [dbo].[sp_CreateMyTable]
    TableName varchar(255)

    AS
    Set QUOTED_Identifier on

    Declare strName varchar(255)

    IF (TableName <> '')
    PRINT 'Table name is ' + TableName
    --RETURN 1

    Set strName=TableName


    CREATE TABLE [dbo].['TableName']
    ([LEV1] [char] (6) COLLATE

    GO
    T Guest

  2. #2

    Default RE: Create Table Using Passed Variables to SP

    /*****************************************
    **
    ** here is a sample hope it helps you
    **
    *****************************************/

    CREATE PROCEDURE SP_Table
    tablename nvarchar(128)
    AS
    DECLARE SQL nvarchar(512)

    SET SQL = 'CREATE TABLE '+tablename+'
    (lev1 char(6))'
    --PRINT SQL
    EXEC sp_executeSQL SQL

    EXECUTE SP_Table 'TEST001'
    -- DROP PROCEDURE SP_Table
    -- DROP TABLE TEST001

    Art Guest

  3. #3

    Default Re: Create Table Using Passed Variables to SP

    http://www.algonet.se/~sommar/dynamic_sql.html

    HTH

    "T" <net> wrote in message
    news:036801c3604f$6941f900$gbl... 


    Amy Guest

Similar Threads

  1. Using ASP Passed Variables in Flash
    By Bobby Schneider in forum Macromedia Flash Data Integration
    Replies: 2
    Last Post: November 8th, 10:06 AM
  2. CFGRID variables not passed
    By where_are_allthenick in forum Coldfusion - Getting Started
    Replies: 1
    Last Post: June 7th, 02:36 PM
  3. Array of passed variables
    By Mike Discenza in forum PHP Development
    Replies: 2
    Last Post: July 31st, 02:24 PM

Bookmarks

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139