在做这个查询时我得到了
转换nvarchar值时转换失败' Dentist'数据类型int。
如何解决这个问题?
select * from tblBusinessCategory as b
inner join tblUser as u
on b.BusinessID=u.BusinessCategoryId
inner join tblAddress as a
on u.AddressId=a.AddressID
where u.BusinessCategoryId in (select BusinessCategory from tblBusinessCategory where BusinessCategory LIKE '%d%')
答案 0 :(得分:3)
问题出在您的嵌套查询中:
in (select BusinessCategory from tblBusinessCategory where BusinessCategory LIKE '%d%')
应该是
in (select BusinessCategoryId from tblBusinessCategory where BusinessCategory LIKE '%d%')
答案 1 :(得分:2)
<强>问题:强>
您正在子查询中选择BusinessCategory
,即varchar。尝试将BusinessCategory
转换为int类型时失败。
<强>解决方案:强>
您应该从表格BusinessCategoryId
中选择tblBusinessCategory
:
............
where u.BusinessCategoryId in (select BusinessCategoryId from tblBusinessCategory where BusinessCategory LIKE '%d%')
修改强>
要对多个列执行类似操作,您可以执行以下操作:
where u.BusinessCategoryId in
(select BusinessCategoryId
from tblBusinessCategory
where BusinessCategory LIKE '%d%'
or BusinessName LIKE '%something%'
or BusinessDescription like '%something%')