Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with insert in sql

Status
Not open for further replies.

monaamit

Technical User
Feb 11, 2005
14
US
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
 
Remove parentheses over SELECTs:
Code:
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

Borislav Borissov
VFP9 SP1, SQL Server 2000/2005.
MVP VFP
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top