我正在尝试这个:
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.
我做错了什么?我看到很多例子做这样的事情,但由于某种原因它根本不起作用。
谢谢!
答案 0 :(得分:8)
我认为[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)) + '%';