Hi,
I have encoutnered the following MySQL statement and would like to
convert it to work with SQL Server 2005.
Is it possible to have two selects inserting into a row and if
affermative, how should it be done?
insert into employee (emp_id, fname, lname, start_date,
dept_id, title, assigned_branch_id)
values (null, 'Susan', 'Barker', '2002-09-12',
(select dept_id from department where name = 'Administration'),
'Vice President',
(select branch_id from branch where name = 'Headquarters'));
Thank You,
AlTry INSERT...SELECT:
INSERT INTO employee (
emp_id,
fname,
lname,
start_date,
dept_id,
title,
assigned_branch_id)
SELECT
NULL,
'Susan',
'Barker',
'2002-09-12',
(SELECT dept_id
FROM department
WHERE name = 'Administration'),
'Vice President',
(SELECT branch_id
FROM branch
WHERE name = 'Headquarters');
Hope this helps.
Dan Guzman
SQL Server MVP
<chribonn@.gmail.com> wrote in message
news:1138537484.578388.31890@.g43g2000cwa.googlegroups.com...
> Hi,
> I have encoutnered the following MySQL statement and would like to
> convert it to work with SQL Server 2005.
> Is it possible to have two selects inserting into a row and if
> affermative, how should it be done?
> insert into employee (emp_id, fname, lname, start_date,
> dept_id, title, assigned_branch_id)
> values (null, 'Susan', 'Barker', '2002-09-12',
> (select dept_id from department where name = 'Administration'),
> 'Vice President',
> (select branch_id from branch where name = 'Headquarters'));
> Thank You,
> Al
>|||insert employee (emp_id, fname, lname, start_date,
dept_id, title, assigned_branch_id)
select null, 'Susan', 'Barker', '2002-09-12',
d.dept_id, 'Vice President', b.branch_id
from department d, branch b
where d.name = 'Administration'
and b.name = 'Headquarters'
"chribonn@.gmail.com" wrote:
> Hi,
> I have encoutnered the following MySQL statement and would like to
> convert it to work with SQL Server 2005.
> Is it possible to have two selects inserting into a row and if
> affermative, how should it be done?
> insert into employee (emp_id, fname, lname, start_date,
> dept_id, title, assigned_branch_id)
> values (null, 'Susan', 'Barker', '2002-09-12',
> (select dept_id from department where name = 'Administration'),
> 'Vice President',
> (select branch_id from branch where name = 'Headquarters'));
> Thank You,
> Al
>|||Thank you for your help.
Regards,
Al
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment