Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Using a variable as the name for a new table

Author  Topic 

Soldano16
Starting Member

2 Posts

Posted - 2008-05-07 : 08:43:52
I work in a Decision Support role and we are moving from Access to SQL Server 2005.

One process we often do in Access is create unique tables for individuals and then export them out as Excel files. We read the person's name from a file and use that variable as the file name.

But I can't find a way to do that in SQL.

I want to do a select into and use the variable as the name but it doesn't work.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-07 : 08:52:40
You can create views and include only those records that are relevant for each user.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-07 : 10:08:10
quote:
Originally posted by Soldano16

I work in a Decision Support role and we are moving from Access to SQL Server 2005.

One process we often do in Access is create unique tables for individuals and then export them out as Excel files. We read the person's name from a file and use that variable as the file name.

But I can't find a way to do that in SQL.

I want to do a select into and use the variable as the name but it doesn't work.


You would require dynamic sql for that

SET @Sql='SELECT * INTO ' + @UserName + ' FROM YourTable WHERE..'
EXEC (@Sql)
where @UserName is username which will be name of your table.
Go to Top of Page

cat_jesus
Aged Yak Warrior

547 Posts

Posted - 2008-05-07 : 10:43:11
Depending on the details of your requirements, Peso is making an excellent suggestion. I have found that having an excel spreadsheet that is linked to a view is something users love. They get their data and it's up to date and there's less work for the DBA.



An infinite universe is the ultimate cartesian product.
Go to Top of Page
   

- Advertisement -