|
Sally1053
Starting Member
7 Posts |
Posted - 2012-02-09 : 07:05:30
|
| hiplease check the code, am not not why its not working SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGOALTER TRIGGER [dbo].[Morena] ON [dbo].[AMGR_User_Fields_Tbl] AFTER INSERT,UPDATEAS BEGINSET NOCOUNT ON;declare @iTCTypeID9 as intdeclare @iTCCodeID9 as intdeclare @bNewID3 as bigintdeclare @iTCTypeID3 as intdeclare @iTCCodeID3 as intdeclare @cClientID3 as varchar(24)declare @cContactNumber3 as intdeclare @description9 as varchar(240)declare @Cell as varchar(24)declare @Work as varchar(24)declare @Fax as varchar(24)declare @Email as varchar(24)declare @PhisicalAddres as varchar(240)declare @KAE as varchar(240)--- Retrieve values been insertedselect @cClientID3 = [Client_Id], @cContactNumber3 = [Contact_Number], @iTCTypeID3 = [Type_Id], @iTCCodeID3 = [Code_Id] from inserted-- Get codes for Primary key Account Executive namesselect @iTCTypeID9 = [Type_Id], @iTCCodeID9 = [Code_Id], @description9 = Description from [AMGR_User_Field_Defs_Tbl] where [Type_Id] = '107' AND [CODE_Id] = @iTCCodeID3-- Pull contact detail from USER DetailsSELECT @Work = User_Phone_1, @Cell = User_Phone_2, @Fax = User_Phone_3, @Email = User_Email_Address ,@PhisicalAddres = user_Address_Line1 +','+ user_Address_Line2 +','+ User_City+','+ user_state_Province +','+ User_Zip_Code FROM ADMN_User_Details WHERE [User_FirstName] + ' ' + [User_Name] = @description9----Check if a KEA name has already been set IF @iTCCodeID9 = @iTCCodeID3 BEGIN If @cContactNumber3 = 0 Begin If exists(select [Record_Id] from [AMGR_User_Fields_Tbl] where [Client_Id] = @cClientID3 and [Code_Id] = @iTCCodeID3) ---- Check if KAE name is populated Begin----- Insert KAE Contact Detailsinsert into [AMGR_User_Fields_Tbl]( [Client_Id], [Contact_Number], [Type_Id], [Code_Id], [Last_Code_Id], [DateCol], [NumericCol], [AlphaNumericCol], [Creator_Id], [Create_Date], [mmddDate], [Modified_By_Id], [Last_Modify_Date] ) select I.[Client_Id], I.[Contact_Number],1091, 0, 0, null, null, R.USER_PHONE_2, I.[Creator_Id], I.[Create_Date], I.[mmddDate], I.[Modified_By_Id], I.[Last_Modify_Date] FROM [dbo].[AMGR_User_Field_Defs_Tbl] AS S INNER JOIN [dbo].[ADMN_User_Details] AS R ON S.DESCRIPTION = R.user_firstname + ' ' + R.user_name INNER JOIN INSERTED AS I ON I.CODE_ID = S.CODE_ID insert into [AMGR_User_Fields_Tbl]( [Client_Id], [Contact_Number], [Type_Id], [Code_Id], [Last_Code_Id], [DateCol], [NumericCol], [AlphaNumericCol], [Creator_Id], [Create_Date], [mmddDate], [Modified_By_Id], [Last_Modify_Date] ) select I.[Client_Id], I.[Contact_Number],1094, 0, 0, null, null, R.USER_EMAIL_ADDRESS, I.[Creator_Id], I.[Create_Date], I.[mmddDate], I.[Modified_By_Id], I.[Last_Modify_Date] FROM [dbo].[AMGR_User_Field_Defs_Tbl] AS S INNER JOIN [dbo].[ADMN_User_Details] AS R ON S.DESCRIPTION = R.user_firstname + ' ' + R.user_name INNER JOIN INSERTED AS I ON I.CODE_ID = S.CODE_ID insert into [AMGR_User_Fields_Tbl]( [Client_Id], [Contact_Number], [Type_Id], [Code_Id], [Last_Code_Id], [DateCol], [NumericCol], [AlphaNumericCol], [Creator_Id], [Create_Date], [mmddDate], [Modified_By_Id], [Last_Modify_Date] ) select I.[Client_Id], I.[Contact_Number],1089, 0, 0, null, null, R.USER_PHONE_3, I.[Creator_Id], I.[Create_Date], I.[mmddDate], I.[Modified_By_Id], I.[Last_Modify_Date] FROM [dbo].[AMGR_User_Field_Defs_Tbl] AS S INNER JOIN [dbo].[ADMN_User_Details] AS R ON S.DESCRIPTION = R.user_firstname + ' ' + R.user_name INNER JOIN INSERTED AS I ON I.CODE_ID = S.CODE_ID insert into [AMGR_User_Fields_Tbl]( [Client_Id], [Contact_Number], [Type_Id], [Code_Id], [Last_Code_Id], [DateCol], [NumericCol], [AlphaNumericCol], [Creator_Id], [Create_Date], [mmddDate], [Modified_By_Id], [Last_Modify_Date] ) select I.[Client_Id], I.[Contact_Number],1088, 0, 0, null, null, R.USER_PHONE_1, I.[Creator_Id], I.[Create_Date], I.[mmddDate], I.[Modified_By_Id], I.[Last_Modify_Date] FROM [dbo].[AMGR_User_Field_Defs_Tbl] AS S INNER JOIN [dbo].[ADMN_User_Details] AS R ON S.DESCRIPTION = R.user_firstname + ' ' + R.user_name INNER JOIN INSERTED AS I ON I.CODE_ID = S.CODE_ID insert into [AMGR_User_Fields_Tbl]( [Client_Id], [Contact_Number], [Type_Id], [Code_Id], [Last_Code_Id], [DateCol], [NumericCol], [AlphaNumericCol], [Creator_Id], [Create_Date], [mmddDate], [Modified_By_Id], [Last_Modify_Date] ) select I.[Client_Id], I.[Contact_Number],1090, 0, 0, null, null, R.user_Address_Line1 +','+ R.user_Address_Line2 +','+ R.User_City+','+ R.user_state_Province +','+ R.User_Zip_Code, I.[Creator_Id], I.[Create_Date], I.[mmddDate], I.[Modified_By_Id], I.[Last_Modify_Date] FROM [dbo].[AMGR_User_Field_Defs_Tbl] AS S INNER JOIN [dbo].[ADMN_User_Details] AS R ON S.DESCRIPTION = R.user_firstname + ' ' + R.user_name INNER JOIN INSERTED AS I ON I.CODE_ID = S.CODE_ID END end end----******----------------------------------------------- UPDATE KAE DETAILS ON CHANGE OF THE ACCOUNT MANAGER----******--------------------------------------------IF UPDATE (Code_Id) AND UPDATE (Type_Id)BEGINSELECT @cClientID3 = [Client_Id], @cContactNumber3 = [Contact_Number], @iTCTypeID3 = [Type_Id], @iTCCodeID3 = [Code_Id] from inserted-- Get codes for Primary key Account Executive namesSELECT @iTCTypeID9 = [Type_Id], @iTCCodeID9 = [Code_Id], @description9 = [Description] from [AMGR_User_Field_Defs_Tbl] where [Type_Id] = '107' AND [CODE_Id] = @iTCCodeID3 and [type_Id]= @iTCTypeID3SELECT @Work = User_Phone_1, @Cell = User_Phone_2, @Fax = User_Phone_3, @Email = User_Email_Address ,@PhisicalAddres = user_Address_Line1 +','+ user_Address_Line2 +','+ User_City+','+ user_state_Province +','+ User_Zip_Code FROM ADMN_User_Details WHERE [User_FirstName] + ' ' + [User_Name] = @description9----- Insert Land line UPDATE U SET AlphanumericCol = @Email FROM AMGR_User_Fields_Tbl U INNER JOIN INSERTED I ON U.Client_id = I.Client_id WHERE U.TYPE_ID = 1094 UPDATE U SET AlphanumericCol = @Work FROM AMGR_User_Fields_Tbl U INNER JOIN INSERTED I ON U.Client_id = I.Client_id WHERE U.TYPE_ID = 1088 UPDATE U SET AlphanumericCol = @Cell FROM AMGR_User_Fields_Tbl U INNER JOIN INSERTED I ON U.Client_id = I.Client_id WHERE U.TYPE_ID = 1091 UPDATE U SET AlphanumericCol = @Fax FROM AMGR_User_Fields_Tbl U INNER JOIN INSERTED I ON U.Client_id = I.Client_id WHERE U.TYPE_ID = 1089 UPDATE U SET AlphanumericCol = @PhisicalAddres FROM AMGR_User_Fields_Tbl U INNER JOIN INSERTED I ON U.Client_id = I.Client_id WHERE U.TYPE_ID = 1090 --end -- EndENDENDSR Masipa |
|