如何从逗号分隔的 guid 字符串中获取可用 guid 的计数
How to get count of available guid from a comma separated string of guid
Declare @i int;
declare @stringOfGuids nvarchar(max)='''70173C2D-0B8E-4043-BD14-665D5DCCF112'',''B0B7445C-DF50-4D49-BD4E-B74958FB0618''
,''70173C2D-0B8E-4043-BD14-665D5DCCF112''';
我有这个字符串,我需要计算可用 guid 的数量,即三个。
如何在整数变量中获取它?
是这样的吗?
select @i = count(@stringOfGuids)
但它 returns 1,我需要三个,因为可用的 guid 是 3。
计算逗号的个数并加1。
SELECT Len(@stringOfGuids ) - Len(Replace( @stringOfGuids , ',', '')) + 1
计数为from this answer。
Declare @i int;
declare @stringOfGuids nvarchar(max)='''70173C2D-0B8E-4043-BD14-665D5DCCF112'',''B0B7445C-DF50-4D49-BD4E-B74958FB0618'' ,''70173C2D-0B8E-4043-BD14-665D5DCCF112''';
declare @cnt int = 0;
declare @pos int = 1;
while charindex('''', @stringOfGuids, @pos) > 0
SELECT @pos = charindex('''', @stringOfGuids, @pos) + 1, @CNT = @CNT + 1;
SELECT @CNT / 2;
Declare @i int;
declare @stringOfGuids nvarchar(max)='''70173C2D-0B8E-4043-BD14-665D5DCCF112'',''B0B7445C-DF50-4D49-BD4E-B74958FB0618''
,''70173C2D-0B8E-4043-BD14-665D5DCCF112''';
我有这个字符串,我需要计算可用 guid 的数量,即三个。
如何在整数变量中获取它?
是这样的吗?
select @i = count(@stringOfGuids)
但它 returns 1,我需要三个,因为可用的 guid 是 3。
计算逗号的个数并加1。
SELECT Len(@stringOfGuids ) - Len(Replace( @stringOfGuids , ',', '')) + 1
计数为from this answer。
Declare @i int;
declare @stringOfGuids nvarchar(max)='''70173C2D-0B8E-4043-BD14-665D5DCCF112'',''B0B7445C-DF50-4D49-BD4E-B74958FB0618'' ,''70173C2D-0B8E-4043-BD14-665D5DCCF112''';
declare @cnt int = 0;
declare @pos int = 1;
while charindex('''', @stringOfGuids, @pos) > 0
SELECT @pos = charindex('''', @stringOfGuids, @pos) + 1, @CNT = @CNT + 1;
SELECT @CNT / 2;