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
 General SQL Server Forums
 New to SQL Server Programming
 Subqueries are not allowed in this context. Only s

Author  Topic 

abundant_lyfe
Starting Member

10 Posts

Posted - 2007-02-20 : 10:47:53
Um, still trying to transpose MySQL into T-SQL.

Inserting info into a table, where one of the columns meets a certain criteria.

insert into employee (/*emp_id,*/ fname, lname, start_date,
dept_id, title, assigned_branch_id)
values (/*null,*/ 'Michael', 'Smith', '2001-06-22',
(select dept_id from department where name = 'Administration'),
'President',
(select branch_id from branch where name = 'Headquarters'));


But I'm getting this error:

Msg 1046, Level 15, State 1, Line 5
Subqueries are not allowed in this context. Only scalar expressions are allowed.


Any help would be greatly appreciated.

jsmith8858
Dr. Cross Join

7423 Posts

Posted - 2007-02-20 : 11:01:05
insert into employee (/*emp_id,*/ fname, lname, start_date, dept_id, title, assigned_branch_id)
select /*null,*/ 'Michael', 'Smith', '2001-06-22', d.dept_id, b.branch_id
from department d
cross join branch b
where d.name = 'Administration' and
b.name = 'Headquarters'


- Jeff
http://weblogs.sqlteam.com/JeffS
Go to Top of Page

abundant_lyfe
Starting Member

10 Posts

Posted - 2007-02-20 : 11:03:44
Thank you Jeff. Hope I don't end up in the Twit List for this. :)
Go to Top of Page
   

- Advertisement -