Sundas Ali

Sundas Ali

  • NA
  • 7
  • 6.9k

i want to fetch id and email from two tables

Jul 10 2016 2:33 PM
ALTER PROC [dbo].[SP_Contact_Msg]<br />--@Reg_id as int,<br />@Email as varchar(50),<br />@txtName as varchar(50),<br />@txtBody as varchar(50),<br />@MsgType as varchar (20)<br />As<br />BEGIN<br /><br />Declare @Reg_Id as int <br />Declare @DriverReg_id as int <br /><br />set @Reg_Id= (select top 1 Reg_ Id from reg where Email=@Email)<br />set @DriverReg_id= (select top 1 DriverReg_id from DriverReg where Email=@Email)<br /><br />if @Reg_id IS NOT NULL AND @DriverReg_id IS NOT NULL<br />BEGIN<br />INSERT INTO Contact(<br />Reg_id,<br />DriverReg_id,<br />Email,<br />txtName,<br />txtBody,<br />MsgType,<br />CreatedOn,<br />CreatedBy,<br />UpdatedBy,<br />UpdatedOn,<br />IsActive)<br />values<br />(<br />@Reg_id<br />,@DriverReg_id<br />,@Email<br />,@txtName<br />,@txtBody<br />,@MsgType<br />,GETDATE()<br />,1<br />,null<br />,null<br />,1)<br />End<br />else<br />BEGIN<br />INSERT INTO Contact(<br />Reg_id,<br />DriverReg_id,<br />Email,<br />txtName,<br />txtBody,<br />MsgType,<br />CreatedOn,<br />CreatedBy,<br />UpdatedBy,<br />UpdatedOn,<br />IsActive)<br />values<br />(<br />null,<br />@Email,<br />@txtName,<br />@txtBody,<br />@MsgType,<br />GETDATE(),<br />1,<br />null,<br />null,<br />1)<br /><br />End<br /><br />End

Answers (3)