|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2004-11-11 : 08:04:37
|
| RANGA writes "HiNeed some insight. Need fresh ideas.Wrote this procedure and would like to polish and optimise it for performance.How do l bcp the data out to a specific location ie c:\DailyFilesHow do l insert the header record into exported textfile ???? Tried xp_cmdshell with echo had no luckis this the best way to handle errors....? How do l insert failed records into an exception tableMove my files from local server to another machine. My move and del statements not working well. Sorry for the long procIF Object_Id('prcInsertNewMatters') Is Not NullDROP PROC prInsertNewMattersGO CREATE PROCEDURE prcInsertNewMatters ASSET NOCOUNT ON/*------------------------------------------------------------------------------------*| Name: dbo.prcInsertNewMatters || Author: Raymond Mahlangu || Date: 09-11-2004 ||-------------------------------------------------------------------------------------|| Purpose: Insert CI Daily Newmatters || Input Parameters: None ||-------------------------------------------------------------------------------------|| Narration : This Procedure populates tbNewmatters with new matters on a daily basis|| Writes Into tbLoadAudit the Table Name,Rows inserted & the Server Name || || Modifications: 09-11-2004 - Raymond Mahlangu (Perfromance Tuning) | *-------------------------------------------------------------------------------------*/DECLARE @IntErrorCode INTSELECT @IntErrorCode = @@ERRORDECLARE @ROWS INTDECLARE @TotalBalance NUMERIC(13,2)---Declare the variables to contain the BCP commandDECLARE @FileName VARCHAR(50), @bcpCommand VARCHAR(2000)DECLARE @Today VARCHAR(10)SET @Today = REPLACE(CONVERT(CHAR(10),'2004-11-05',120 ),'-','/')BEGIN TRANSACTIONIF @IntErrorCode = 0 BEGIN TRUNCATE TABLE tbNewMatters --insert new matters INSERT INTO tbNewMatters ( CustomerReference ,AccountReference ,OverDueBal ,TransactionDate ,Currency ,[Language] ,AttorneyCurrent ,ReasonCode ,TakeonPrevReasonCode ,InstalmetAmount )SELECT DISTINCT /** Check if the Ci client has an ABIL ClientNo & Populate the Field Otherwise generate one from custcode **/ CASE WHEN c.IdentificationNumber IS NULL THEN SUBSTRING(CONVERT(VARCHAR(10),a.CUSTCODE),3,5 ) ELSE c.CLIENTNUMBER END AS CustomerReference ,CONVERT(VARCHAR(15) , a.CustCode ) AS AccountReference ,CONVERT(NUMERIC(13,2) , a.Arrears ) AS OverDueBal /** To get Date Format of YYYY/MM/DD **/ ,REPLACE( CONVERT( CHAR(10),a.AccountOpenDate,120 ),'-','/' ) AS TransactionDate ,CONVERT(VARCHAR(3) ,'ZAR' ) AS Currency ,CONVERT(VARCHAR(3) ,'EN' ) AS Language ,LTRIM(LTRIM(CONVERT(CHAR(4),NULL))) AS AttorneyCurrent /** Translate Flags to ABIL Flags **/ ,CASE WHEN a.AgencyNumber = 1 THEN CONVERT(NUMERIC(3,0),143 ) WHEN a.AgencyNumber = 2 THEN CONVERT(NUMERIC(3,0),850 ) WHEN a.AgencyNumber = 130 OR a.AgencyNumber = 3 THEN CONVERT(NUMERIC(3,0),400 ) ELSE CONVERT(NUMERIC(3,0),NULL ) END AS ReasonCode ,CONVERT(NUMERIC(3,0) ,Null ) AS TakeonPre |
|