Inserting foreign key values

Posted by Self-innovator under Sql Server on 1/9/2012 | Points: 10 | Views : 1053 | Status : [Member] | Replies : 2
Consider these 3 tables
table1-tbCompanyData
CompanyID CompanyName
1 ABB
2 DELL
table2-tbQuestion
Code QnDescription
1 How you rate our services
2 How is our products
3 How do you think about us

tbale 3-tbQnRating
CompanyID QnCode Rating

1 1 3
2 1 2
2 2 3
3 1 1
My Stored Procedure
create proc [dbo].[sp_InsertAllValues]
@CompanyName varchar(100),
@Rating int
as
declare @topId int
set @topId=(select MAX(ID+1) from tbCompanyData)
declare @QnCode int
set @QnCode=(select code from tbQnMst where Code=1)(NOTE:I'm inserting the QnCode values statically here so in my table according to the QnCOde 1 companyName,QnCode and rating are getting inserted so please tell me how do i insert QnCode dynamically)
begin
begin try
begin transaction
insert into tbCompanyData values(@CompanyName)
insert into tbQnRating values(@topId,@QnCode,@Rating)
commit transaction
end try
begin catch
rollback transaction
end CATCH
end


Pls do the needful..It's urgent

Join Hands Change lives
Thanks & Regards
Straight Edge Society



Responses

Posted by: Sksamantaray on: 1/9/2012 [Member] Silver | Points: 25

Up
0
Down

can you generate and attach your table str script , here so that it will be easier for rectify quickly

Thanks,
Sanjay

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Self-innovator on: 1/9/2012 [Member] Bronze | Points: 25

Up
0
Down
you pls rectify it...

Join Hands Change lives
Thanks & Regards
Straight Edge Society

Self-innovator, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response