【发布时间】:2018-09-10 05:46:39
【问题描述】:
如果我们将值 In 子句从 'Canada,Portugal' 转换为 'Canada','Portugal' 传递,则 SQL 查询不起作用 如果在子句 'Canada','Portugal' 中通过硬编码值,它会起作用
declare @GeographicalLocation varchar(max)
set @GeographicalLocation ='Canada,Portugal'
set @GeographicalLocation = REPLACE(@GeographicalLocation, ',', ''',''')
set @GeographicalLocation = ''''+@GeographicalLocation+'''';
select ContinentName from [ContinentList] where ContinentId in
(select ContinentId from [CountryList] where [CountryName]
in(@GeographicalLocation)and BaseId is Null)
【问题讨论】:
-
你应该试试
split()函数并加入它。 -
为什么不工作?
-
您不是在传递一个列表,而是在传递一个包含值
Canada,Portugal的字符串,并且不能在in子句中使用字符串