all groups > sql server mseq > june 2007 >
You're in the

sql server mseq

group:

Help adding fields to a table


Help adding fields to a table Dan
6/28/2007 12:50:04 PM
sql server mseq:
I have a list of values in one field in a table, and I want to modify another
table that I have to add a new field for each value in the other field. In
case this doesn't make sense, I've posted examples below -

Table 1
Field 1
values - Apple, Pear, Banana, Orange

Table 2
I want to create four fields, one for each of the values in field 1 of table 1


I thought about doing this as a loop, but the only way I see to create a
field is using alter table, and that only allows me to enter a text name for
the field, instead of calling another field or value from another field.

Any ideas on how to do this? If it matters, I'm using SQL Query Analyzer
v.8.0.


Thanks,
Dan
RE: Help adding fields to a table Mohit K. Gupta
6/29/2007 11:06:03 AM
You can use something like this ..

DECLARE @SQL varchar(8000)

SET @SQL = 'SELECT * FROM SYSDATABASES'

EXEC (@SQL)

Create a dynamic query and execute it using EXEC.

Thanks!
--
Mohit K. Gupta
B.Sc. CS, Minor Japanese
MCTS: SQL Server 2005


[quoted text, click to view]
AddThis Social Bookmark Button