Combine insert select statements with known value

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi!

Is it possible to combine insert statement with one known value and one
returned by select statement, eg.

insert into Table (u_id, dep_id)
values (2354, select dep_id from Department where dep_id = (
select max(dep_id) from Department)

Thanks!

Peter
 
Hi!

Is it possible to combine insert statement with one known value and one
returned by select statement, eg.

insert into Table (u_id, dep_id)
values (2354, select dep_id from Department where dep_id = (
select max(dep_id) from Department)

Thanks!

Peter

Yes, by including the known value as a calculated field in the Select,
and using the Select form Insert rather than the Values:

INSERT INTO table(U_ID, Dep_ID)
SELECT 2354 AS U_ID, Dep_ID FROM Department WHERE dep_id =
(select max(dep_id) from Department);


John W. Vinson[MVP]
Join the online Access Chats
Tuesday 11am EDT - Thursday 3:30pm EDT
http://community.compuserve.com/msdevapps
 
Back
Top