I am new in SQL, I am trying to insert data from two tables into one table. I am deleting the data before adding new data. If I run individual queries it runs, If I run all together the table is empty. Please HELP!!!!
Here is my query.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[UpdatePastDueBills]
AS
delete FROM TblPastDueBills
INSERT INTO [PastDuePersonalPropery].[dbo].[TblPastDueBills]
([record_type],[Notice_Date],[Levy_Type],[c_cid_city],[c_cid_state],[addr1],[Account_Code],[Name1],[Name2],
[c_the_prefix],[addr2],[CSZ],[c_cid_country],[Account_Number],[Interest_Date] ,[Levy_Year],[Levy_Bill_Number],
[Levy_Partial_Payments],[a_ar_category],[a_customer_name],[Levy_Total_Tax],[bd_adjust_amount],[Levy_Tax_Balance],
[bh_lien_flag],[a_charge_code],[bh_date1_bill],[bh_date2_bill],[bh_date3_bill],[bh_date4_bill],
[bh_date1_interest],[bh_date2_interest],[bh_date3_interest],[bh_date4_interest],[Last_Date],
[InterestDate],[Levy_Interest],[Levy_Amount_Due])
(Select record_type,Notice_Date,Levy_Type,c_cid_city,c_cid_state,addr1,Account_Code,Name1,Name2,
c_the_prefix,addr2,CSZ,c_cid_country,Account_Number,Interest_Date ,Levy_Year,Levy_Bill_Number,
Levy_Partial_Payments,a_ar_category,a_customer_name,Levy_Total_Tax,bd_adjust_amount,Levy_Tax_Balance,
bh_lien_flag,a_charge_code,bh_date1_bill,bh_date2_bill,bh_date3_bill,bh_date4_bill,
bh_date1_interest,bh_date2_interest,bh_date3_interest,bh_date4_interest,Last_Date,
InterestDate,Levy_Interest,Levy_Amount_Due from vPastDuefor30days)
INSERT INTO [PastDuePersonalPropery].[dbo].[TblPastDueBills]
([record_type],[Notice_Date],[Levy_Type],[c_cid_city],[c_cid_state],[addr1],[Account_Code],[Name1],[Name2],
[c_the_prefix],[addr2],[CSZ],[c_cid_country],[Account_Number],[Interest_Date] ,[Levy_Year],[Levy_Bill_Number],
[Levy_Partial_Payments],[a_ar_category],[a_customer_name],[Levy_Total_Tax],[bd_adjust_amount],[Levy_Tax_Balance],
[bh_lien_flag],[a_charge_code],[bh_date1_bill],[bh_date2_bill],[bh_date3_bill],[bh_date4_bill],
[bh_date1_interest],[bh_date2_interest],[bh_date3_interest],[bh_date4_interest],[Last_Date],
[InterestDate],[Levy_Interest],[Levy_Amount_Due])
(Select record_type,Notice_Date,Levy_Type,c_cid_city,c_cid_state,addr1,Account_Code,Name1,Name2,
c_the_prefix,addr2,CSZ,c_cid_country,Account_Number,Interest_Date ,Levy_Year,Levy_Bill_Number,
Levy_Partial_Payments,a_ar_category,a_customer_name,Levy_Total_Tax,bd_adjust_amount,Levy_Tax_Balance,
bh_lien_flag,a_charge_code,bh_date1_bill,bh_date2_bill,bh_date3_bill,bh_date4_bill,
bh_date1_interest,bh_date2_interest,bh_date3_interest,bh_date4_interest,Last_Date,
InterestDate,Levy_Interest,Levy_Amount_Due from vPastDuewithSameAccountsforMoreThan30days)
Thanks
Here is my query.
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go
ALTER PROCEDURE [dbo].[UpdatePastDueBills]
AS
delete FROM TblPastDueBills
INSERT INTO [PastDuePersonalPropery].[dbo].[TblPastDueBills]
([record_type],[Notice_Date],[Levy_Type],[c_cid_city],[c_cid_state],[addr1],[Account_Code],[Name1],[Name2],
[c_the_prefix],[addr2],[CSZ],[c_cid_country],[Account_Number],[Interest_Date] ,[Levy_Year],[Levy_Bill_Number],
[Levy_Partial_Payments],[a_ar_category],[a_customer_name],[Levy_Total_Tax],[bd_adjust_amount],[Levy_Tax_Balance],
[bh_lien_flag],[a_charge_code],[bh_date1_bill],[bh_date2_bill],[bh_date3_bill],[bh_date4_bill],
[bh_date1_interest],[bh_date2_interest],[bh_date3_interest],[bh_date4_interest],[Last_Date],
[InterestDate],[Levy_Interest],[Levy_Amount_Due])
(Select record_type,Notice_Date,Levy_Type,c_cid_city,c_cid_state,addr1,Account_Code,Name1,Name2,
c_the_prefix,addr2,CSZ,c_cid_country,Account_Number,Interest_Date ,Levy_Year,Levy_Bill_Number,
Levy_Partial_Payments,a_ar_category,a_customer_name,Levy_Total_Tax,bd_adjust_amount,Levy_Tax_Balance,
bh_lien_flag,a_charge_code,bh_date1_bill,bh_date2_bill,bh_date3_bill,bh_date4_bill,
bh_date1_interest,bh_date2_interest,bh_date3_interest,bh_date4_interest,Last_Date,
InterestDate,Levy_Interest,Levy_Amount_Due from vPastDuefor30days)
INSERT INTO [PastDuePersonalPropery].[dbo].[TblPastDueBills]
([record_type],[Notice_Date],[Levy_Type],[c_cid_city],[c_cid_state],[addr1],[Account_Code],[Name1],[Name2],
[c_the_prefix],[addr2],[CSZ],[c_cid_country],[Account_Number],[Interest_Date] ,[Levy_Year],[Levy_Bill_Number],
[Levy_Partial_Payments],[a_ar_category],[a_customer_name],[Levy_Total_Tax],[bd_adjust_amount],[Levy_Tax_Balance],
[bh_lien_flag],[a_charge_code],[bh_date1_bill],[bh_date2_bill],[bh_date3_bill],[bh_date4_bill],
[bh_date1_interest],[bh_date2_interest],[bh_date3_interest],[bh_date4_interest],[Last_Date],
[InterestDate],[Levy_Interest],[Levy_Amount_Due])
(Select record_type,Notice_Date,Levy_Type,c_cid_city,c_cid_state,addr1,Account_Code,Name1,Name2,
c_the_prefix,addr2,CSZ,c_cid_country,Account_Number,Interest_Date ,Levy_Year,Levy_Bill_Number,
Levy_Partial_Payments,a_ar_category,a_customer_name,Levy_Total_Tax,bd_adjust_amount,Levy_Tax_Balance,
bh_lien_flag,a_charge_code,bh_date1_bill,bh_date2_bill,bh_date3_bill,bh_date4_bill,
bh_date1_interest,bh_date2_interest,bh_date3_interest,bh_date4_interest,Last_Date,
InterestDate,Levy_Interest,Levy_Amount_Due from vPastDuewithSameAccountsforMoreThan30days)
Thanks