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
 Help with procedure

Author  Topic 

nnogueira
Starting Member

18 Posts

Posted - 2010-02-03 : 13:45:02
Friends, I need a little help here with a command.

The situation is as follows:

I have a table containing usernames (NCHAR (100)), I would run a command for each User found in this table, based on their behalf for the command, because each User has a database with your own name in system.

Select UserName from tbluser

Theoretically the return of the users would have:

Username: UserXYZ

The user XYZ has a single database on their behalf, eg

UserXYZDataBase1

And in this has a particular table, called tblResults. I would like to implement a change in it. Example

Alter table UserXYZDataBase1.tblResults
ADD COLUMNNAME INT


I would like to include, for each user found in the select command, a column in this particular table within each database separate User.

The command, I imagine that would be something like:

Declare @ UserNameFound
Set @ UsernameFound = Null
Select @ UserNameFound = [UserName] From tbluser
WHILE @ UserNameFound IS NOT NULL
BEGIN
Alter Table UserNameFound @ + 'UserXYZDataBase1.tblResults
END


Any ideas?

Thank you for your attention...

Kristen
Test

22859 Posts

Posted - 2010-02-03 : 14:26:14
Looks all right, but you need to use Dynamic SQL for the "Alter Table" command
Go to Top of Page
   

- Advertisement -