Combine insert select statements with known value

P

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
 
J

John Vinson

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top