Unix Technical Forum

SQL Server 2000 Varchar limit

This is a discussion on SQL Server 2000 Varchar limit within the SQL Server forums, part of the Microsoft SQL Server category; --> I pass a comma-delimitted string of numbers to a sproc that can be huge. I'm using this Split function ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 03-06-2008, 03:04 PM
evanburen@gmail.com
 
Posts: n/a
Default SQL Server 2000 Varchar limit

I pass a comma-delimitted string of numbers to a sproc that can be
huge. I'm using this Split function to break up the list of numbers by
comma. It works great but only holds up to the varchar limit of 8000
and my requirements often exceed that. I think SQL Server 2005 uses a
new MAX property for varchars but I'm still using SQL Server 2000. Is
this any way to overcome this? Thanks.


CREATE PROCEDURE [dbo].[up_ExportQuickSearchresults]
@p_selectedDirectors VARCHAR(8000)
AS
BEGIN

SELECT * FROM v_QuickSearchResults
WHERE IDDir in (SELECT IDDir FROM split(@p_selectedDirectors, ','))
END GO



CREATE FUNCTION dbo.Split
(
@ItemList VARCHAR(8000),
@delimiter CHAR(1)
)
RETURNS @IDTable TABLE (IDDir VARCHAR(8000))
AS

BEGIN
DECLARE @tempItemList VARCHAR(8000)
SET @tempItemList = @ItemList

DECLARE @i INT
DECLARE @IDDir VARCHAR(8000)

SET @tempItemList = REPLACE (@tempItemList, ' ', '')
SET @i = CHARINDEX(@delimiter, @tempItemList)

WHILE (LEN(@tempItemList) > 0)
BEGIN
IF @i = 0
SET @IDDir = @tempItemList
ELSE
SET @IDDir = LEFT(@tempItemList, @i - 1)
INSERT INTO @IDTable(IDDir) VALUES(@IDDir)
IF @i = 0
SET @tempItemList = ''
ELSE
SET @tempItemList = RIGHT(@tempItemList,
LEN(@tempItemList) - @i)
SET @i = CHARINDEX(@delimiter, @tempItemList)
END
RETURN
END
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 03-06-2008, 03:04 PM
Plamen Ratchev
 
Posts: n/a
Default Re: SQL Server 2000 Varchar limit

A few ways to handle this:

1). Pass multiple VARCHAR parameters to the stored procedure
2). Pass TEXT parameter to the stored procedure and internally splice the
TEXT to VARCHAR chunks and process
3). Pass TEXT parameter that contains XML formatted values rather than list,
then use OPENXML to process

Take a look at this article by Erland Sommarskog for details on some of the
techniques, as well as different methods to split a list to optimize that
part too:
http://www.sommarskog.se/arrays-in-sql-2000.html

In particular those two sections:
http://www.sommarskog.se/arrays-in-s...lnum-unlimited
http://www.sommarskog.se/arrays-in-s...0.html#OPENXML

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 03:37 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com