dbTalk Databases Forums  

CSV Field Stored Procedure

microsoft.public.sqlserver.clients microsoft.public.sqlserver.clients


Discuss CSV Field Stored Procedure in the microsoft.public.sqlserver.clients forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Steve
 
Posts: n/a

Default CSV Field Stored Procedure - 06-18-2004 , 02:28 AM






Hi All,

I would like to submit a large amount of CSV text into a stored procedure. At present I'm using a varchar(8000) parameter and then converting this into a temporary table using something like the sql below. My question is does anybody have any suggestions on how to get round the 8000 limit without doing round trips?

thanks

Steve

declare @separator char(3)

set @separator = '%' + @delimeter + '%'

declare @separator_position int
declare @array_value varchar(1000)

set @input = @input + ','

while patindex(@separator , @input) <> 0
begin

select @separator_position = patindex(@separator , @input)
select @array_value = left(@input, @separator_position - 1)

Insert @IntTable
Values (@array_value)

select @input = stuff(@input, 1, @separator_position, '')
end

Reply With Quote
  #2  
Old   
Keith Kratochvil
 
Posts: n/a

Default Re: CSV Field Stored Procedure - 06-18-2004 , 11:09 AM






Multiple parameters?

--
Keith


"Steve" <steve (AT) nospam (DOT) com> wrote

Hi All,

I would like to submit a large amount of CSV text into a stored procedure. At present I'm using a varchar(8000) parameter and then converting this into a temporary table using something like the sql below. My question is does anybody have any suggestions on how to get round the 8000 limit without doing round trips?

thanks

Steve

declare @separator char(3)

set @separator = '%' + @delimeter + '%'

declare @separator_position int
declare @array_value varchar(1000)

set @input = @input + ','

while patindex(@separator , @input) <> 0
begin

select @separator_position = patindex(@separator , @input)
select @array_value = left(@input, @separator_position - 1)

Insert @IntTable
Values (@array_value)

select @input = stuff(@input, 1, @separator_position, '')
end

Reply With Quote
  #3  
Old   
Steve Kass
 
Posts: n/a

Default Re: CSV Field Stored Procedure - 06-19-2004 , 02:41 PM



Steve,

You can pass the CSV text as a parameter of type text or ntext, and use PATINDEX and SUBSTRING to parse it. An alternative, that if possible will make parsing the long parameter much easier is to pass it as non-separated text with a fixed-length field width instead of comma-separated. You can find an example of this technique at http://www.sommarskog.se/arrays-in-s...ixstring_multi, and the entire article http://www.sommarskog.se/arrays-in-sql.html may also be useful.

Steve Kass
Drew University
"Steve" <steve (AT) nospam (DOT) com> wrote

Hi All,

I would like to submit a large amount of CSV text into a stored procedure. At present I'm using a varchar(8000) parameter and then converting this into a temporary table using something like the sql below. My question is does anybody have any suggestions on how to get round the 8000 limit without doing round trips?

thanks

Steve

declare @separator char(3)

set @separator = '%' + @delimeter + '%'

declare @separator_position int
declare @array_value varchar(1000)

set @input = @input + ','

while patindex(@separator , @input) <> 0
begin

select @separator_position = patindex(@separator , @input)
select @array_value = left(@input, @separator_position - 1)

Insert @IntTable
Values (@array_value)

select @input = stuff(@input, 1, @separator_position, '')
end

Reply With Quote
  #4  
Old   
Steve
 
Posts: n/a

Default Re: CSV Field Stored Procedure - 06-20-2004 , 12:53 PM



Many thanks for your help guys.

Regards

Steve
"Steve" <steve (AT) nospam (DOT) com> wrote

Hi All,

I would like to submit a large amount of CSV text into a stored procedure. At present I'm using a varchar(8000) parameter and then converting this into a temporary table using something like the sql below. My question is does anybody have any suggestions on how to get round the 8000 limit without doing round trips?

thanks

Steve

declare @separator char(3)

set @separator = '%' + @delimeter + '%'

declare @separator_position int
declare @array_value varchar(1000)

set @input = @input + ','

while patindex(@separator , @input) <> 0
begin

select @separator_position = patindex(@separator , @input)
select @array_value = left(@input, @separator_position - 1)

Insert @IntTable
Values (@array_value)

select @input = stuff(@input, 1, @separator_position, '')
end

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.