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
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
"Dan" wrote:
> 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
>
No comments:
Post a Comment