Wrox Home  
Search P2P Archive for: Go

  Return to Index  

sql_language thread: Creating tables from existing data


Message #1 by "burton" <burton@w...> on Wed, 6 Sep 2000 15:38:09 +0100
In SQL Server you can try something like this:

DECLARE @SQLString varchar(255)

SELECT @SQLString = 'SELECT * INTO' + theName + 'FROM SFUsers WHERE theUser 
' + theUser
FROM SFUsers
WHERE theUser = ?

This will dynamically build a SQL statement for each user.
You can then execute the string by coding :
EXEC(@SQLString)
or
EXEC sp_executesql @SQLString, @ParmDefinition, @theUser = ?...
See BOL for info on sp_executesql

Note: this is SQL Server 7.0 syntax

HTH

P.







burton wrote:

> Hi,
>
> Given this:
>
> SELECT *
> INTO ""
> FROM SFUsers
> WHERE (theUser = ?)
>
> How would one name the newly created table with that of the name where
> (theUser = ?)
>
> Here's the problem:
> I have a db with 273 unique users, userids etc. What I would like to do is
> create a separate table for each user which will contain their data. As
> stated above, I'd like to have each table named in respect to the user's
> name. Ideas?
>
> Thanks in advance
>

  Return to Index