A select statement within an insert statement

mike55

Well-known member
Joined
Mar 26, 2004
Messages
726
Location
Ireland
Hi all,

Am wondering is it possible to do a select statement within an insert statement.
Code:
insert into Groups (Group_ID, Group_Name, Group_Description, Org_ID)  Values ((Select @temp = Max(Group_ID from Groups), @gName,@gDesc,@OrgID)

Mike55
 
Never trying it before, and not knowing what database your using, Id say yes =D though Id modify the query

insert into Groups (Group_ID, Group_Name, Group_Description, Org_ID) Values ((Select Max(Group_ID) from Groups), @gName,@gDesc,@OrgID)
 
MS SQL Example

The example below works for MS SQL. To include a select statement in an insert you have to create a "derived table". The derived table must match the structure of the table being inserted.

I hope this helps.
-- Bryant

Code:
insert Groups 
	select Group_ID , Group_Name, Group_Description, Org_ID 
	from Groups 
	where Group_ID = ( select Max( Group_ID ) from Groups )
 
Back
Top