﻿

-- =============================================
-- Author:		S.E. Locatelli
-- Create date: 2013.11.28
-- Description:	Procedura per conversioen e tipizzazione dati da tmp a ext x ClientsRaw
-- =============================================
CREATE PROCEDURE [tmp].[convertClientsRaw]
(
	 @fileType NVARCHAR(50) = 'ClientsRaw'
)
AS
BEGIN
	SET NOCOUNT ON;

	-- per Giancarlo: rendere parametrico con esecuzione sql x poter inserire nei parametri il separatore ed il resto? http://www.sqlteam.com/article/using-bulk-insert-to-load-a-text-file
	
	IF @fileType = 'ClientsRaw'
		BEGIN
			-- svuoto tabella temp
			TRUNCATE TABLE ext.ClientsRaw

			-- inserisco con cast valori...
			INSERT ext.ClientsRaw
            WITH (TABLOCK)
            ( CodClient, ClientName, CodAg, ZipCode, City, [State], Nation, TranspZone) 
            SELECT
                   CodClient,
                   ClientName,
                   CodAg,
                   ZipCode,
                   City,
				   [State],
				   Nation,
				   TranspZone
            FROM tmp.ClientsRaw;

			SELECT COUNT(*)  as RecordsIn FROM ext.ClientsRaw
		END

END


