![](/img/trans.png)
[英]Conversion failed when converting character string to uniqueidentifier error from asp.net application but not from SQL Server Management Studio
[英]ASP.NET/SQL Server: Conversion failed when converting from a character string to uniqueidentifier
我為此使用參數化查詢。 我正在將逗號分隔的唯一標識符字符串傳遞給此查詢的已拆分參數。 使用幾個唯一的標識符,它可以正常工作,但我想我達到了約2000個字符的最大值。
我大約有150個areaID,選擇一些查詢即可正常工作。 選擇查詢失敗並返回的所有區域
從字符串轉換為uniqueidentifier時轉換失敗。
在不遇到此問題的情況下獲取更多值查詢的任何建議?
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.