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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 inserting 1+1 column

Author  Topic 

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2007-11-10 : 15:48:26
Hi,

i have searched and haven't found anything that might helped me solve this problem.

i have to tables:
-------------------
create table id1
(id_person int not null,
country char(5) not null)
go

insert into id1 (id_person, country) values (1, 'ALMBA')
insert into id1 (id_person, country) values (2, 'NEYOR')
insert into id1 (id_person, country) values (3, 'SEATT')
insert into id1 (id_person, country) values (4, 'LOSAN')


create table ID2
(id_person int not null)
go
insert into ID2 (id_person) values (12)
insert into ID2 (id_person) values (13)
insert into ID2 (id_person) values (14)
insert into ID2 (id_person) values (15)
------------------------------

what i want now is to insert id2.id_person into id1.id_person whereas id1.country should be generated for all the same eg.: LOSAN

Eg.:

insert into id1 (id_person, country)
select i.id_person from ID2
and --add country -- country = 'LOSAN'

So I don't know how to structure the rest of the query that i get the results added in ID1

12, 'LOSAN'
13, 'LOSAN'
14, 'LOSAN'
15, 'LOSAN'

thank you

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-10 : 15:52:17
Insert Into id1 (idperson,country)
Select id_person,'LOSAN'
FROM ID2
Go to Top of Page

slimt_slimt
Aged Yak Warrior

746 Posts

Posted - 2007-11-10 : 15:54:07

insert into id1 (id_person, country)
select id_person, (select 'LOSAN') from ID2

just wrote it myself too ;)
Go to Top of Page

dataguru1971
Master Smack Fu Yak Hacker

1464 Posts

Posted - 2007-11-10 : 16:34:01
you don't need the multiple Selects I don't think.
Go to Top of Page
   

- Advertisement -