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)
 Insert multiple values to a table from another

Author  Topic 

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2008-09-01 : 08:20:10
Hello.
I have a table named useracclimits and i want to add values from another table named puser.
I get my values from the puser table like this :
select id from puser
where activeacceptancerange=1
and expiredate is null
--- kai na do mono tous iusers
and name like 'iuser%'


Now i want to add the id to the useracclimits table + another value (18)

The useracclimits table has a id, userid(where i want to add the id of the puser table) and a acclimitid id that will always be 18.


I'm thinking of






insert into useracclimits values ((select id from puser
where activeacceptancerange=1
and expiredate is null
--- kai na do mono tous iusers
and name like 'iuser%'),18)


But will it work and since i have a primary key do i need another value? (pk value, the select id from puser stuff,18)?
Can you help me?
Thanks.

georgev
Posting Yak Master

122 Posts

Posted - 2008-09-01 : 08:52:19
[CODE]
INSERT INTO useracclimits (field1, field2)
SELECT id, 18
FORM puser
WHERE activeacceptancerange = 1
AND expiredate IS NULL
AND name like 'iuser%'
[/CODE]


George
Go to Top of Page

sapator
Constraint Violating Yak Guru

462 Posts

Posted - 2008-09-01 : 09:01:35
Thanks mate!
Go to Top of Page
   

- Advertisement -