我正在尝试:
SELECT FacilityID, FacilityName, CMSProviderID, [Provider Number]
FROM G2_Facility, SCIPHospitalCompare
WHERE [Provider Number] LIKE '%' + CMSProviderID + '%';
我得到:
Msg 245, Level 16, State 1, Line 1
Conversion failed when converting the varchar value '%' to data type int.
我究竟做错了什么?我看到很多例子都在做这样的事情,但是由于某种原因,它根本不起作用。
谢谢!
最佳答案
我假设[Provider Number]
或CMSProviderID
是一个数字字段?
将数字字段转换为字符串以比较两者:
SELECT FacilityID, FacilityName, CMSProviderID, [Provider Number]
FROM G2_Facility, SCIPHospitalCompare
WHERE CAST([Provider Number] as nvarchar(50)) LIKE
'%' + CAST(CMSProviderID as nvarchar(50)) + '%';
关于sql - 如何在LIKE语句中串联%和列名,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11318276/