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.
| 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 tbluserTheoretically the return of the users would have:Username: UserXYZThe user XYZ has a single database on their behalf, egUserXYZDataBase1And in this has a particular table, called tblResults. I would like to implement a change in it. ExampleAlter table UserXYZDataBase1.tblResultsADD COLUMNNAME INTI 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 @ UserNameFoundSet @ UsernameFound = NullSelect @ UserNameFound = [UserName] From tbluserWHILE @ UserNameFound IS NOT NULLBEGINAlter Table UserNameFound @ + 'UserXYZDataBase1.tblResultsENDAny 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 |
 |
|
|
|
|
|