Hi Team,
if it is possible take excel as input to stored procedure? if it is possible please help on same.
Excel input Data | ||||||
clientName | businessType | contactFName | contactLName | contactEmail | ||
AAClient1 | 1 | Hema | raj | hema@gmail.com | ||
AAClient2 | 1 | ram | k | hema@gmail.com | ||
AAClient3 | 2 | Sarath | r | hema@gmail.com | ||
AAClient4 | 2 | A | C | hema@gmail.com | ||
AAClient5 | 1 | B | D | hema@gmail.com | ||
AAClient6 | 1 | E | Z | hema@gmail.com | ||
SQL output Table | ||||||
ClentId | clientName | AccountNumber | businessType | contactFName | contactLName | contactEmail |
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