Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

How to take excel as input for procedure in SSIS package

$
0
0

Hi Team,

if it is possible  take excel as input to stored procedure? if it is possible please help on same.

Excel input  Data
clientNamebusinessTypecontactFNamecontactLNamecontactEmail
AAClient11Hemarajhema@gmail.com
AAClient21ramkhema@gmail.com
AAClient32Sarathrhema@gmail.com
AAClient42AChema@gmail.com
AAClient51BDhema@gmail.com
AAClient61EZhema@gmail.com
SQL output Table
ClentIdclientNameAccountNumberbusinessTypecontactFNamecontactLNamecontactEmail

As using bellow sp and function in SSIS package.

                        

--- Procedure

CREATE PROCEDURE [dbo].[usp_AddClientInfo]       
@clientName varchar(50),    
@accountNumber varchar(50),    
@businessType tinyint,    
@contactFName varchar(50),    
@contactLName varchar(50),    
@contactEmail varchar(50)
AS    
BEGIN    
 -- SET NOCOUNT ON added to prevent extra result sets from    
 -- interfering with SELECT statements.    
 SET NOCOUNT ON;    

    -- Insert statements for procedure here    
 INSERT INTO     
 TableName(clientName,accountNumber,businessType,contactFName,    
 contactLName,contactEmail)    
 VALUES    
 (@clientName,@accountNumber,@businessType,@contactFName,@contactLName,    
  @contactEmail)     
 SET @clientId= @@IDENTITY    

 -- This will update the client account number with MCN.  
 update TableName set accountNumber=dbo.genAccountCode(@clientId)     
 where clientId=@clientId    

END  


--- Function

CREATE FUNCTION [dbo].[genAccountCode] (@clientid int )
returns varchar(50)
begin

declare @AccNumber varchar(50) = ''
declare @MCNLength int

            set @MCNLength = len(@clientid)

            IF @MCNLength=1
            BEGIN
            SET  @AccNumber='MCN'+'00000'+CAST(@clientid AS VARCHAR)
            END
            ELSE IF @MCNLength=2
            BEGIN
            SET @AccNumber='MCN'+'0000'+CAST(@clientid AS VARCHAR)
            END
            ELSE IF @MCNLength=3
            BEGIN
            SET @AccNumber='MCN'+'000'+CAST(@clientid AS VARCHAR)
            END
            ELSE IF @MCNLength=4
            BEGIN
            SET @AccNumber='MCN'+'00'+CAST(@clientid AS VARCHAR)
            END
            ELSE IF @MCNLength=5
            BEGIN
            SET @AccNumber='MCN'+'0'+CAST(@clientid AS VARCHAR)
            END
            ELSE IF @MCNLength=6
            BEGIN
            SET @AccNumber='MCN'+''+CAST(@clientid AS VARCHAR)
            END

RETURN @AccNumber
end


Thanks Bala Narasimha


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>