-- Exec pr_str '6*88*2*10,7*99*4*9'
Create Procedure [dbo].[pr_str] @MultipleData Varchar(6000)
As
Declare @SplitMultipleData Varchar(50),@SplitMultipleDataToIndivisual Varchar(50)
Declare @Data1 BigInt,@Data2 NVarchar(50),@Data3 BigInt,@Data4 BigInt,@Counter BigInt
Declare MultipleData Cursor For
Select Distinct String As D1D2D3D4 From FN_Split(@MultipleData,',')
Open MultipleData
Fetch Next From MultipleData InTo @SplitMultipleData
While @@FETCH_STATUS = 0
Begin
Set @Counter = 1
Declare SplitOnebyOne Cursor For
Select String As ParticularData From FN_Split(@SplitMultipleData,'*')
Open SplitOnebyOne
Fetch Next From SplitOnebyOne InTo @SplitMultipleDataToIndivisual
While @@FETCH_STATUS = 0
Begin
If (@Counter=1)
Set @Data1 = Cast(@SplitMultipleDataToIndivisual As BigInt)
If (@Counter=2)
Set @Data2 = Cast(@SplitMultipleDataToIndivisual As NVarchar)
If (@Counter=3)
Set @Data3 = Cast(@SplitMultipleDataToIndivisual As BigInt)
If (@Counter=4)
Set @Data4 = Cast(@SplitMultipleDataToIndivisual As BigInt)
Set @Counter = @Counter + 1
Fetch Next From SplitOnebyOne InTo @SplitMultipleDataToIndivisual
End
Close SplitOnebyOne
Deallocate SplitOnebyOne
insert into OMG (S_Name,S_Age,S_Sex,S_Hobbies) values
( @Data1 ,@Data2,@Data3, @Data4)
Fetch Next From MultipleData InTo @SplitMultipleData
End
Close MultipleData
Deallocate MultipleData
-- Select * FROM OMG
-- Truncate Table OMG
Create Procedure [dbo].[pr_str] @MultipleData Varchar(6000)
As
Declare @SplitMultipleData Varchar(50),@SplitMultipleDataToIndivisual Varchar(50)
Declare @Data1 BigInt,@Data2 NVarchar(50),@Data3 BigInt,@Data4 BigInt,@Counter BigInt
Declare MultipleData Cursor For
Select Distinct String As D1D2D3D4 From FN_Split(@MultipleData,',')
Open MultipleData
Fetch Next From MultipleData InTo @SplitMultipleData
While @@FETCH_STATUS = 0
Begin
Set @Counter = 1
Declare SplitOnebyOne Cursor For
Select String As ParticularData From FN_Split(@SplitMultipleData,'*')
Open SplitOnebyOne
Fetch Next From SplitOnebyOne InTo @SplitMultipleDataToIndivisual
While @@FETCH_STATUS = 0
Begin
If (@Counter=1)
Set @Data1 = Cast(@SplitMultipleDataToIndivisual As BigInt)
If (@Counter=2)
Set @Data2 = Cast(@SplitMultipleDataToIndivisual As NVarchar)
If (@Counter=3)
Set @Data3 = Cast(@SplitMultipleDataToIndivisual As BigInt)
If (@Counter=4)
Set @Data4 = Cast(@SplitMultipleDataToIndivisual As BigInt)
Set @Counter = @Counter + 1
Fetch Next From SplitOnebyOne InTo @SplitMultipleDataToIndivisual
End
Close SplitOnebyOne
Deallocate SplitOnebyOne
insert into OMG (S_Name,S_Age,S_Sex,S_Hobbies) values
( @Data1 ,@Data2,@Data3, @Data4)
Fetch Next From MultipleData InTo @SplitMultipleData
End
Close MultipleData
Deallocate MultipleData
-- Select * FROM OMG
-- Truncate Table OMG
No comments:
Post a Comment