inserting values from select query
-
hi guys i have one insert query in which i am selecting values from another table and then insert it in first table Query is like this. usergroup(userid,groupid) group(groupid,groupname,owner) i have values of userid and groupname when i am inserting new group. So i have to also insert values in usergroup table because owner is also member of group. insert into usergroup(userid,groupid) values (userid,select groupid from group where groupname="temp")) it is not working so if anyone knows how to do it please help me out DJ
-
hi guys i have one insert query in which i am selecting values from another table and then insert it in first table Query is like this. usergroup(userid,groupid) group(groupid,groupname,owner) i have values of userid and groupname when i am inserting new group. So i have to also insert values in usergroup table because owner is also member of group. insert into usergroup(userid,groupid) values (userid,select groupid from group where groupname="temp")) it is not working so if anyone knows how to do it please help me out DJ
-
Use a select in the insert. Example:
insert into Table2 (SomeField, AnotherField) select @SomeData, AnotherField from Table1 where SomeId = @SomeId
--- b { font-weight: normal; }
-
thanks for your answer i have tried this but i dont have stored procedure and i want to fetch data from table and both data are coming from different table so tell me some other solution