想运行select dbo.[Func_GetCountOfColorsByColorName]('103:468:49F:996')就知道里面有多少个引号,但不懂怎么去判断字符串,:(ALTER FUNCTION [dbo].[Func_GetCountOfColorsByColorName]
(
@ColorName nvarchar(4000)
)
RETURNS numeric(18)
AS
BEGIN
DECLARE @Result numeric(18)
DECLARE @Length numeric(18) IF (@ColorName!='' AND @ColorName is not null)
BEGIN
SET @Length = Len(@ColorName)
WHILE @Length>0
BEGIN
--CHARINDEX(':', @ColorName, 1)
--写到最重要的部分不懂了,希望大家指点一下,应该怎么样去一个个字母去数然后判断是不是引号呢? SET @Result = @Length
SET @Length = @Length -1
END
END RETURN @ResultEND
(
@ColorName nvarchar(4000)
)
RETURNS numeric(18)
AS
BEGIN
DECLARE @Result numeric(18)
DECLARE @Length numeric(18) IF (@ColorName!='' AND @ColorName is not null)
BEGIN
SET @Length = Len(@ColorName)
WHILE @Length>0
BEGIN
--CHARINDEX(':', @ColorName, 1)
--写到最重要的部分不懂了,希望大家指点一下,应该怎么样去一个个字母去数然后判断是不是引号呢? SET @Result = @Length
SET @Length = @Length -1
END
END RETURN @ResultEND
set @num = 0
WHILE @start <= @Length
begin
@ColumnName = substring( @ColorName , @start , 1)
set @start = @start + 1
if @ColumnName = ';'
set @num = @num + 1
end
试试:
declare @str varchar(1000)
set @str='123:34219:43::2'
select len(@str)-len(replace(@str,':',''))