Dynamic Table Names - Using

  • I have a situation where we will actually want to create separate tables for a number of country dial codes. Each table will be extacly the same. SO we wish to start with a template and create the tables, throught a stored procedure, whiwh will assign a table name based upon the contents of another table. Thus, a table name will be row1col1+row1col2 which would then be used as the table name with an assigned prefix. SO @tablename = @prefix + row1col1+row1col2.

    Next we will CREATE TABLE @TableName.......

    and so on....

    The only problem IS when I use @TableName that is exaactly what I get, and not the contents of the vaiable.

    I KNOW this is not a great idea, but it is something Sales wants and we have had a BIG problem using one large table ( WHICH we already have ).

    Any suggestions ?

    Thanks...

    Edited by - spartanx15 on 01/04/2003 2:39:46 PM

  • Not a great idea. Why doesnt the big table work? Maybe you could post DDL and describe the problem, perhaps we can offer you some alternatives.

    For your current problem, the only way to do it is to build up a string, then execute the string using either Exec() or sp_executesql, in either case whoever runs it has to have the appropriate permissions not just on the proc, but to create/alter the objects.

    Andy

    http://qa.sqlservercentral.com/columnists/awarren/

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply