假设XXXX
,或列中的@@@@
任何其他值仅显示为占位符,也可以使用 sql server 实现您的目标。像这样的查询会做到这一点:CharString
Table2
DECLARE @CharString VARCHAR(100)
DECLARE @ValueString VARCHAR(100)
DECLARE @SearchString VARCHAR(100)
DECLARE @ResultString VARCHAR(100)
SELECT @SearchString = stringval FROM Table1
SELECT @ResultString = stringval FROM Table1
DECLARE c CURSOR FAST_FORWARD FOR
SELECT CharString, ValueString
FROM Table2
OPEN c
FETCH NEXT FROM c INTO @CharString, @ValueString
WHILE @@FETCH_STATUS = 0
BEGIN
IF PATINDEX('%' + @CharString + '%', @SearchString) <> 0
SET @ResultString = REPLACE(@ResultString, @CharString, @ValueString)
FETCH NEXT FROM c INTO @CharString, @ValueString
END
CLOSE c
DEALLOCATE c
SELECT @ResultString