Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 insert one value from one table to another

Author  Topic 

fm88
Starting Member

18 Posts

Posted - 2008-10-29 : 06:06:41
i have 2 tables : tblMember(memberid,name,...) and tblmemberServiceRole

i want to insert in tblmemberServiceRole
-max(memberid) from tblMember
-servicerole which is another variable


in the same query
thanks

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-29 : 06:08:55
[code]insert into tblmemberServiceRole
select max(memberid),@servicerole from tblMember[/code]
Go to Top of Page

fm88
Starting Member

18 Posts

Posted - 2008-10-29 : 06:24:13
@servicerole is not a column in tblMember...in tblmemberServiceRole the first column max(memberid) and the second column is another value...
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-29 : 06:26:37
quote:
Originally posted by fm88

@servicerole is not a column in tblMember...in tblmemberServiceRole the first column max(memberid) and the second column is another value...


i know that. where does that value come from? i thought you would sending it through parameter thats why i gave parameter name.
Go to Top of Page

ursangel
Starting Member

17 Posts

Posted - 2008-10-29 : 11:31:43
fm88 please be clear on the input values for the tblMemberServiceRole
what visakh16 has mentioned in correct.
Its a simple insert into select statement.
But specify the 2nd column value.

declare @servicerole varchar(50);
set @servicerole = 'Test' -- change to the role description
insert into tblmemberServiceRole
select max(memberid),@servicerole from tblMember



Regards
Angel
Go to Top of Page
   

- Advertisement -