使用sql server 2005 DB中的存储过程,过程有一段查询
.
.
.
if(@zipCodeList <> '')
BEGIN
SET @zipCodeList = ''''+replace(replace(replace(@zipCodeList, ' ', ''),',',''','''),'_',' ')+''''
END
SELECT distinct ZIPCode
from zip_table
where ZIPCode_col IN (@zipCodeList)
AND power((69.1 * (abs(Longitude) - abs(Longitude)) * cos(abs(Latitude)/57.3)),2) +
Power(69.1 * (abs(Latitude) - abs(Latitude)), 2) <= (60 * 60)
AND more conditions
.
.
.
调用类似
的过程exec proc '02124, 23568'
数据库有记录,但程序没有显示任何内容,我打印了查询并打印
SELECT distinct ZIPCode
from zip_table
where ZIPCode_col IN ('02124','23568')
AND power((69.1 * (abs(Longitude) - abs(Longitude)) * cos(abs(Latitude)/57.3)),2) +
Power(69.1 * (abs(Latitude) - abs(Latitude)), 2) <= (60 * 60)
AND more conditions
当我运行此查询时,返回正确的结果。看起来像@zipCodeList
在运行时引起了一些问题,但没有给出任何错误,任何人都可以在我错误的地方帮助我。
提前致谢。
答案 0 :(得分:0)
如果@zipCodeList的值为1,2,3
,则执行以下代码
SELECT distinct ZIPCode
from zip_table
where ZIPCode_col IN
(
SELECT PARSENAME(REPLACE(Split.a.value('.', 'VARCHAR(500)'),'-','.'),1) 'Ids'
FROM
(
SELECT CAST ('<M>' + REPLACE(@zipCodeList, ',', '</M><M>') + '</M>' AS XML) AS Data
) AS A
CROSS APPLY Data.nodes ('/M') AS Split(a)
)
AND power((69.1 * (abs(Longitude) - abs(Longitude)) * cos(abs(Latitude)/57.3)),2) +
Power(69.1 * (abs(Latitude) - abs(Latitude)), 2) <= (60 * 60)
AND more conditions