我正在尝试这个:
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.
我究竟做错了什么?我看到很多例子都在做这样的事情,但由于某些原因它完全不起作用.
谢谢!
解决方法
我假设[提供者编号]或CMSProviderID是数字字段?
将数字字段转换为字符串以比较两者:
SELECT FacilityID,[Provider Number] FROM G2_Facility,SCIPHospitalCompare WHERE CAST([Provider Number] as nvarchar(50)) LIKE '%' + CAST(CMSProviderID as nvarchar(50)) + '%';