日期:2014-05-18 浏览次数:20574 次
Create Table Test3(aa int,bb nvarchar(200)) go Insert INTO Test3 values(1,'广东省深圳市深圳火车站深圳火车站') -- 这行有重复的 Insert INTO Test3 values(2,'北京市海淀区委') Insert INTO Test3 values(3,'广东省深圳市广东省深圳市火车站') -- 这行有重复的 Insert INTO Test3 values(4,'我家住在黄土高坡') Insert INTO Test3 values(5,'湖南省长沙市万家丽路123号万家丽路123号') -- 这行有重复的 GO CREATE FUNCTION CheckString(@str nvarchar(200)) RETURNS integer AS BEGIN DECLARE @Length INT DECLARE @Point INT DECLARE @Substring NVARCHAR(100) DECLARE @SubPoint INT DECLARE @Gap INT DECLARE @DoHave INT DECLARE @StrTemp NVARCHAR(100) SET @Point = 1 SET @Gap = 5 SET @DoHave = 0 SET @Length = LEN(@Str) WHILE @Gap + @Point <= @Length BEGIN SET @StrTemp = @Str WHILE @Point + @Gap <= @Length BEGIN SET @Substring = SUBSTRING(@Str,@Point,@Gap) SET @StrTemp = REPLACE(@Str,@Substring,'') IF LEN(@StrTemp) < @Length - @Gap BEGIN SET @DoHave = 1 SET @Point = @Length END SET @Gap = @Gap + 1 END SET @Point = @Point + 1 SET @Gap = 5 END RETURN @DoHave END SELECT * FROM Test3 WHERE dbo.CheckString(bb) > 0