I am using a paramterized query for this. I am passing a comma-delimited string of unique identifiers to this query's parameters which are split. It works fine using a couple of unique identifiers but I think I am hitting a max value around 2000 characters.
I have around 150 areaID's and selecting a few the query works fine. Selecting all of the areas the query fails and returns
Conversion failed when converting from a character string to uniqueidentifier.
Any suggestions for getting more values into query without running into this issue?
Area.AreaID IN (SELECT CONVERT(UNIQUEIDENTIFIER, Value) FROM dbo.Split(@AreaIDs,','))
/
USE [Triton2]
GO
/****** Object: UserDefinedFunction [dbo].[Split] Script Date: 12/11/2012 11:39:39 AM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER FUNCTION [dbo].[Split]
(
@List nvarchar(2000),
@SplitOn nvarchar(5)
)
RETURNS @RtnValue table
(
Id int identity(1,1),
Value uniqueidentifier
)
AS
BEGIN
While (Charindex(@SplitOn,@List)>0)
Begin
Insert Into @RtnValue (value)
Select
Value = ltrim(rtrim(Substring(@List,1,Charindex(@SplitOn,@List)-1)))
Set @List = Substring(@List,Charindex(@SplitOn,@List)+len(@SplitOn),len(@List))
End
Insert Into @RtnValue (Value)
Select Value = ltrim(rtrim(@List))
Return
END