Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi all,

 

Am wondering is it possible to do a select statement within an insert statement.

insert into Groups (Group_ID, Group_Name, Group_Description, Org_ID)  Values ((Select @temp = Max(Group_ID from Groups), @gName,@gDesc,@OrgID)

 

Mike55

A Client refers to the person who incurs the development cost.

A Customer refers to the person that pays to use the product.

------

My software never has bugs. It just develops random features. (Mosabama vbforums.com)

Posted

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

 

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

Posted

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

 

insert Groups 
select Group_ID , Group_Name, Group_Description, Org_ID 
from Groups 
where Group_ID = ( select Max( Group_ID ) from Groups )

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...