如何替换特定单词

时间:2018-09-13 05:38:46

标签: sql sql-server tsql

CREATE TABLE TESTDE(
Query VARCHAR(150)
);

INSERT INTO TESTDE VALUES ('SELECT EmployeeName FROM EmployeeTable WHERE FirstName = ''Asim'' AND LastName = ''Asghar'' AND EducationLevel = ''School''');


SELECT * FROM TESTDE
SELECT REPLACE(Query, '=', '<>') FROM TESTDE 

我有此表和一个查询。我只想用此查询中保存的内容替换特定的单词。 例如,我的要求是仅在=之后用<>替换EducationLevel。我有查询,但是它用=替换了所有<>

1 个答案:

答案 0 :(得分:2)

如果您希望替换=之后的EducationLevel,则可以使用“ EducationLevel =”进行选择。因此,您的查询应类似于:

SELECT REPLACE(Query, 'EducationLevel =', 'EducationLevel <>') FROM TESTDE