New to stored procedures I have just created this to
update two tables in my db
Problem is when the procedure is executed
the first table has the records inserted but the second is not
Any pointers as to why would be very helpful
CREATE PROCEDURE [dbo].[sp_AddNewUser]
(
@tbUsr_BadgeNo varchar(50), @tbUsr_First char(50), @tbUsr_Last char(50), @tbUsr_Company char(50), @tbUsr_Address1 char(50), @tbUsr_Address2 char(50), @tbUsr_Town char(50)
, @tbUsr_County char(50), @tbUsr_Country char(50), @tbUsr_PostZip varchar(50)
,@tbUsr_Telno varchar(20), @tbUsr_FaxNo varchar(20), @tbUsr_Email varchar(50)
,@tbLog_passphrase char(10)
)
AS
Begin
INSERT INTO [dbTophorse].[dbo].[tbUser]( [tbUsr_BadgeNo], [tbUsr_First], [tbUsr_Last], [tbUsr_Company], [tbUsr_Address1], [tbUsr_Address2], [tbUsr_Town], [tbUsr_County], [tbUsr_Country], [tbUsr_PostZip], [tbUsr_Telno], [tbUsr_Fax], [tbUsr_Email])
VALUES(@tbUsr_BadgeNo, @tbUsr_First,@tbUsr_Last, @tbUsr_Company, @tbUsr_Address1, @tbUsr_Address2, @tbUsr_Town, @tbUsr_County, @tbUsr_Country, @tbUsr_PostZip, @tbUsr_TelNo, @tbUsr_FaxNo, @tbUsr_Email)
Declare @Usr_Id int
Set @Usr_Id=@@IDENTITY
Declare @LoginSql varchar(8000)
Set @LoginSql='INSERT INTO [dbTophorse].[dbo].[tbLogin]( [tbUsr_id], [tbUsr_BadgeNo], [tbLog_passphrase])
VALUES(' + Convert(int,@Usr_Id) + ',' + Convert(int, @tbUsr_BadgeNo)+','+ Convert(varchar, @tbLog_passphrase)+')'
exec(@LoginSql)
End
update two tables in my db
Problem is when the procedure is executed
the first table has the records inserted but the second is not
Any pointers as to why would be very helpful
CREATE PROCEDURE [dbo].[sp_AddNewUser]
(
@tbUsr_BadgeNo varchar(50), @tbUsr_First char(50), @tbUsr_Last char(50), @tbUsr_Company char(50), @tbUsr_Address1 char(50), @tbUsr_Address2 char(50), @tbUsr_Town char(50)
, @tbUsr_County char(50), @tbUsr_Country char(50), @tbUsr_PostZip varchar(50)
,@tbUsr_Telno varchar(20), @tbUsr_FaxNo varchar(20), @tbUsr_Email varchar(50)
,@tbLog_passphrase char(10)
)
AS
Begin
INSERT INTO [dbTophorse].[dbo].[tbUser]( [tbUsr_BadgeNo], [tbUsr_First], [tbUsr_Last], [tbUsr_Company], [tbUsr_Address1], [tbUsr_Address2], [tbUsr_Town], [tbUsr_County], [tbUsr_Country], [tbUsr_PostZip], [tbUsr_Telno], [tbUsr_Fax], [tbUsr_Email])
VALUES(@tbUsr_BadgeNo, @tbUsr_First,@tbUsr_Last, @tbUsr_Company, @tbUsr_Address1, @tbUsr_Address2, @tbUsr_Town, @tbUsr_County, @tbUsr_Country, @tbUsr_PostZip, @tbUsr_TelNo, @tbUsr_FaxNo, @tbUsr_Email)
Declare @Usr_Id int
Set @Usr_Id=@@IDENTITY
Declare @LoginSql varchar(8000)
Set @LoginSql='INSERT INTO [dbTophorse].[dbo].[tbLogin]( [tbUsr_id], [tbUsr_BadgeNo], [tbLog_passphrase])
VALUES(' + Convert(int,@Usr_Id) + ',' + Convert(int, @tbUsr_BadgeNo)+','+ Convert(varchar, @tbLog_passphrase)+')'
exec(@LoginSql)
End