希望这看起来不太简单。我已经看了这个,但我不擅长SQL用户定义的函数和它们的使用,所以我不知道发生了什么。谁幻想告诉我为什么我收到错误几点:运行SQL用户定义的函数返回布尔值,在where子句中
An expression of non-boolean type specified in a context where a condition is expected, near ')'.
对于这一点:
UPDATE LMI_Contact
SET Phone = NULL
WHERE dbo.LMI_IsSingleCharacterRepeated(Phone, '0')
其中函数可以使用创建:
-- ***this will also find NULL and empty string values***
CREATE FUNCTION LMI_IsSingleCharacterRepeated (@string varchar(max), @char char(1))
RETURNS bit
AS
BEGIN
DECLARE @index int
DECLARE @len int
DECLARE @currentChar char(1)
SET @index = 1
SET @len= LEN(@string)
WHILE @index <= @len
BEGIN
SET @currentChar = SUBSTRING(@string, @index, 1)
IF @currentChar = @char
SET @index= @index+ 1
ELSE
RETURN 0
END
RETURN 1
END;
GO
此功能用于检查一个字符串是否是任何指定的单个字符,重复。希望有人认为它有用!
谨慎 - 我的功能也将找到空值或空字符串字段,所以真的需要一些更多的工作 –