SQL语句截取单个汉字的方法及字符串替换语句
SELECT @AA=REVERSE(SUBSTRING(REVERSE(@ItemName),1,LEN(@ItemName))) --取汉字字串
SELECT @CHAR=SUBSTRING(@AA,1,1) --取单个汉字
DECLARE @SourceName VARCHAR(10),@TargetName VARCHAR(10),@ItemCode varchar(12),@ReplaceItemName varchar(100),@ItemName varchar(100)
SET @SourceName='MDT10P509S11'
SET @TargetName='HMC10P1509'
DECLARE CursorProcName CURSOR FOR
SELECT ItemCode,ItemName
FROM OITM
WHERE ItemName LIKE '%'+@SourceName+'%'
OPEN CursorProcName
WHILE 1 = 1 BEGIN
FETCH NEXT FROM CursorProcName INTO @ItemCode,@ItemName
IF @@fetch_status <> 0
BREAK
SET @ReplaceItemName = REPLACE(@ItemName,@SourceName,@TargetName)
UPDATE OITM SET ItemName = @ReplaceItemName WHERE ItemCode=@ItemCode
END
CleanUp:
CLOSE CursorProcName
Deallocate cursorProcName
SELECT @ItemCode
SELECT @ItemName
RETURN
E_General_Error:
/* this is an all or nothing. No specific error messages */
goto CleanUp
E_OAError:
goto CleanUp
曹玉平:男 湖南郴州桥口排塘曹家