希望這看起來不太簡單。我已經看了這個,但我不擅長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
此功能用於檢查一個字符串是否是任何指定的單個字符,重複。希望有人認爲它有用!
謹慎 - 我的功能也將找到空值或空字符串字段,所以真的需要一些更多的工作 –