|
I am generating bulk invoices using front end and when I try to insert it to the data base it takes hours it’s unacceptable.
This is how I am doing the task
Get relevant Cx accounts to data tables
Generates Invoice header and detail records and store those records on Invoice Header and Detail Data tables
Loop the invoice header data table and Insert recodes using Strode procedure.
Loop the invoice detail data table and Insert recodes using Strode procedure.
To generate for 200000 invoices it takes more than 24 Hrs.
How can I improve the performance?
Please refer the code.
//Inserting the Invoice Header records
foreach(DataRow InvHDR in DS_BillData.Tables["InvoiceHeaderInformation"].Rows)
{
SqlParameter[] para =new SqlParameter[14];
para[0]=new SqlParameter("@GUAccountID",InvHDR["GUAccountID"]);
para[1]=new SqlParameter("@GUInvID",InvHDR["GUInvoiceID"]);
para[2]=new SqlParameter("@InvoiceNo",InvHDR["InvoiceNo"]);
para[3]=new SqlParameter("@InvoiceDate",StartDate);
para[4]=new SqlParameter("@DueDate",DueDate);
para[5]=new SqlParameter("@BatchNo",BatchID);
para[6]=new SqlParameter("@GUStatmentID",InvHDR["GUInvoiceID"]);
para[7]=new SqlParameter("@BatchSNCount",BatchSNCount);
para[8]=new SqlParameter("@PAYMENTRECIVED",InvHDR["PAYMENTRECIVED"]);
para[9]=new SqlParameter("@SubTotal",InvHDR["SubTotal"]);
para[10]=new SqlParameter("@InvoiceAmount",InvHDR["InvoiceAmount"]);
para[11]=new SqlParameter("@VAT",InvHDR["VAT"]);
para[12]=new SqlParameter("@OtherTax",InvHDR["OtherTax"]);
para[13]=new SqlParameter("@StatmentNo",InvHDR["InvoiceNo"]);
//para[13]=new SqlParameter("@WaveOFF","Y");
callSp("BillingInvoiceCreation_forFront",para);
}
Stored Procedure---
Procedure BillingInvoiceCreation_forFront
(
@GUAccountID as nvarchar(30),
@GUInvID as nvarchar(30),
@InvoiceNo as numeric,
@InvoiceDate as datetime,
@DueDate as datetime,
@BatchNo as Decimal,
@GUStatmentID as nvarchar(30),
@StatmentNo as numeric,
@BatchSNCount as decimal,
@PAYMENTRECIVED as decimal(9,2),
@SubTotal as decimal(9,2),
@InvoiceAmount as decimal(9,2),
@VAT as decimal(9,2),
@OtherTax as decimal(9,2)
)
as
BEGIN
Declare @PrintDescription as nvarchar(100)
Declare @GUItemID as nvarchar(30)
Declare @PaymentAmt as decimal(9,2)
Declare @DueAmount as decimal(9,2)
Declare @CreditNoteAmount as decimal(9,2)
Declare @BFAmount as decimal(9,2)
INSERT INTO B_BillingInvoiceHeader(StatementNo, GUStatementID, GUInvID,
CompanyID, LocationID, BranchID, DeptID, InvoiceNo,
InvoiceDate, DueDate, Status, GUAccountID, ManualInvoice,
BatchNo, InvoiceType,BatchSNCount,BillingYear,BillingMonth,SubTotal,InvoiceAmount,VAT,OtherTax)
VALUES(@StatmentNo, @GUStatmentID, @GUInvID,
1, 1, 1, 1, @InvoiceNo,
@InvoiceDate, @DueDate, 'New', @GUAccountID, 'N',
@BatchNo, 'Batch',@BatchSNCount,year(@InvoiceDate),month(@InvoiceDate),@SubTotal,@InvoiceAmount,@VAT,@OtherTax)
SELECT @BFAmount=isnull(SUM(InvoiceAmount - PaidAmount),0)
FROM B_BillingInvoiceHeader
WHERE (GUAccountID = @GUAccountID) AND (PaymentCompleted = N'N') AND BatchNo<@BatchNo
/*_________________ Add Sanka ______________________*/
exec BillingCustomerAdvances @GUInvID
--- Late Invoice Delocate-----------------------------------------------------------------<<(*_*)>>-----
SELECT @PaymentAmt = PaymentReceve From B_CustomerPaymentRec Where GUAccountID=@GUAccountID And BatchNo=@BatchNo
SELECT @CreditNoteAmount=isnull(SUM(Amount) ,0)
FROM B_CreditNote
WHERE (Status='APPROVED') And (Completed ='N') AND (GUAccountID = @GUAccountID)
INSERT INTO B_MonthlyOpenningBalance
(GuAccountID, BatchNo, OppenningBalance, ClosingBalance, CreditNote, AdvanceBalance, UtilizedCredits)
VALUES (@GuAccountID, @BatchNo, @BFAmount, @BFAmount+@InvoiceAmount, @CreditNoteAmount, 0, 0)
INSERT INTO B_MonthlyBF
(CompanyID, LocationID, BranchID, DeptID, BatchNo, BFAmount, GUAccountID)
VALUES (1, 1, 1, 1, @BatchNo, @BFAmount, @GUAccountID)
Update B_CreditNote Set Completed ='Y' WHERE (Status='APPROVED') And (Completed ='N') AND (GUAccountID = @GUAccountID)
END
------
Thanks for the help i am working on DTS update method con any one give me a direction or small sample code kind of a thing?
Regards,
Daminda.
modified on Friday, December 21, 2007 9:30:11 AM
|
|
|
|
|
You should examine the execution plans for your queries and use the Profiler tool to identify the bottlenecks in your code.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Have you considered using something like DTS or SSIS instead. They are set up to bulk load data.
|
|
|
|
|
Hi I wish to create a custom auto generate ID, such as P110, P111 which is generated automatically is there ways to set it in sql server?Thanks alot
|
|
|
|
|
You can set an int column to be an IDENTITY field to generate sequential numbers in that field. If you want your sequence to be alphanumeric, you should create a computed column for that purpose.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
Hi
can any one knows how to establish database connection with java script
thanks in advance
|
|
|
|
|
rajesh4u wrote: can any one knows how to establish database connection with java script
You could use "Astoria" - now known as ADO.NET data services: Astoria website[^]
|
|
|
|
|
You can do it using Ajax only.
If u r using VS 2005, u can use the Ajax control toolkit for this purpose
|
|
|
|
|
Hi,
I created a SQL Linked server for excel file. I am using that Linked server to Import the data from Excel files.When selecting the reords from this linked server , it returns the data in alphabetical order.
But I want the same order of columns which is in Excel file.
for selecting the records i am using tis Query:
select * from ExcelImport...Test$
where, ExcelImport is Linked server name and Test$ is the sheet in the excel file.
Please help.
kalam.
|
|
|
|
|
Can you not provide the named columns in the select statement:
e.g. Select cola, othercolumnname from excelimport
|
|
|
|
|
hi,
I need to login to remote sql server trough my Application and need to change the server location
|
|
|
|
|
Is there a problem you are having? Your post is too vague.
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
i need a query for checkin a name whether it exists or not in database,,
am storing firstname nd lastname in seperate columns.
bt if i enter a first name only in textbox i need to display all names(firstname+lastname) ,starting from the entered first name
PLZ HELP...
Waiting 4 reply...
|
|
|
|
|
Hi Mithun,
Please try this. Hope it will help you.
if exists(select ID from Tablename where nameFirst like '%Your TextBox Value%')<br />
<br />
select nameFirst + SPACE(1) + nameLast As Name from Tablename where nameFirst like '%Your TextBox Value%'
Keep Smiling
|
|
|
|
|
Thank u Boss its Workin nw...
bt am passing the name as a parameter
where cand_fname like @cand_fname
its nt wrking
bt if give as cand_fname like 'mith'
this works
so how change that
|
|
|
|
|
k i got that ive changed to
where cand_fname like '%'+@cand_fname+'%'
thnk u.....
|
|
|
|
|
how to get system date without time in
SQL Server 2005
thanks
You get the best out of others when you give the best of yourself.
|
|
|
|
|
Hi,
Try this
select convert(varchar(50),getdate(),101)
Regards.
Keep Smiling
|
|
|
|
|
Thank u so much
It's working fine.
You get the best out of others when you give the best of yourself.
|
|
|
|
|
Maybe i've overlooked it, but can someone tell me how I could get a list of all the tables in a database once i've connected? (C#).
Thankyou.
Mark.
|
|
|
|
|
It depends on what type of database you're using. People at CodeProject aren't psychic, so you'll have to provide that information if you want help.
Paul Marfleet
"No, his mind is not for rent
To any God or government"
Tom Sawyer - Rush
|
|
|
|
|
If you using SQL Server
Try this
select object_name(id) from sysObjects where type = 'u'
N.Rajakumar B.E.,
Application Developer,
|
|
|
|
|
Microsoft® SQL Server™ 2008 provides a comprehensive data platform that is more secure, reliable, manageable and scalable for your mission critical applications. Developers can create new applications that can store and consume any type of data on any device. Users can make informed decisions with relevant insights.
To take advantage of the new features in your products, Microsoft is offering several training opportunities.
A 10-part web seminar series covers topics ranging from high availability to manageability, security, business intelligence, and reporting. January 8 – January 30 at 9:00 AM PST. Learn more and register for the Microsoft SQL Server 2008 training web seminars. Some of the sessions include the hot business intelligence (BI) topics:
For more information of interest to developers, see the Microsoft US ISV blog[^]
|
|
|
|
|
Can someone help me with 2 issues that I have? My first issue is when I try to print out that the user account exist with the following line: PRINT 'The login ' + @login_name + ' already exists.'
I receive the following error: Server: Msg 446, Level 16, State 8, Line 45
Cannot resolve collation conflict for concatenation operation.
What can I do to solve this?
My second issue is I'm trying to have this procedure work for both Sql 2000 and Sql 2005. I currently using 2000 for testing but in 2005 to create a user login the line of code: --CREATE USER 'username' FOR LOGIN 'loginname' creates a syntax error. Is there anyway around this?
DECLARE @sqlVersion char(2)
DECLARE @login_name char(12)
DECLARE @loginpassword char(12)
DECLARE @username char(12)
DECLARE @dbase char(8)
SET @login_name = loginname
SET @loginpassword = password
SET @username = username
SET @dbase = password
SELECT @sqlVersion = SUBSTRING(CAST(SERVERPROPERTY('productversion') AS char),1,1)
use database
IF NOT EXISTS(SELECT name FROM sysxlogins WHERE name = @login_name)
IF @sqlVersion = 8
BEGIN
EXEC sp_addlogin @login_name, @loginpassword, @dbase
EXEC sp_grantdbaccess @login_name, @username
EXEC sp_addrolemember 'db_datareader', @username
EXEC sp_addrolemember 'db_datawriter', @username
/* Grant the account access to the rms database */
use database
EXEC sp_grantdbaccess @login_name, @username
/* Grant rights to the STORED PROCEDURES */
BEGIN TRANSACTION
USE database
GRANT EXECUTE ON SP TO username
IF @@ERROR <> 0 GOTO err_handler
PRINT '----User was successfully created ----'
COMMIT TRANSACTION
END
ELSE
PRINT 'The login ' + @login_name + ' already exists.'
IF @sqlVersion = 9
BEGIN
EXEC sp_addlogin @login_name, loginpassword, @dbase
--CREATE USER 'opcenteruser' FOR LOGIN 'opcenteruser'
EXEC sp_addrolemember 'db_datareader', @username
EXEC sp_addrolemember 'db_datawriter', @username
use database
EXEC sp_grantdbaccess login_name, @username
EXEC sp_addrolemember 'db_datareader', @username
BEGIN TRANSACTION
/* Grant rights to the STORED PROCEDURES */
USE database
GRANT PERMISSIONS TO STORED PROCEDURES....
IF @@ERROR <> 0 GOTO err_handler
PRINT '----User was successfully created ----'
COMMIT TRANSACTION
END
RETURN
err_handler:
ROLLBACK TRANSACTION
RAISERROR ('Failed to commit transaction.', 16,1)
RETURN
GO
Terrance C.
|
|
|
|
|
Hi everybody,
I'm using MSSQL2005 to build a report system and I need to create some views in order to speed up the execution of queries, but I need these views created so that the WHERE clause contains dynamic values, like parameters or so. If I write this as a simple query, it would be as follows:
SELECT some_field FROM my_table WHERE another_field = @my_parameter
of course, the query I want turned into a view is much more complex, but the point here is the WHERE part and the use of a parameter.
So, I'm wondering if there's a way of using the view somehow that I can specify this parameter.
If anyone knows if this can be done and how to do it, please, let me know.
Thanks in advance
Cheers,
Kenia
|
|
|
|
|