【发布时间】:2013-09-11 09:30:33
【问题描述】:
我想应用条件 where 子句也就是说,如果我的 barcode 参数为空,那么我想获取所有记录,如果它带有值,那么我想只获取第二部分的匹配记录,我能够获取匹配的记录,但我坚持在空值的情况下获取所有记录,我尝试如下,
SELECT item
FROM tempTable
WHERE
((ISNULL(@barcode,0)=1)
// but this is not fetching all the records if barcode is null
OR
ISNULL(@barcode,0!= 1 AND tempTable.barcode LIKE @barcode+'%'))
//THis is working perfect
所以任何帮助都会很棒
【问题讨论】:
-
ISNULL(@barcode,0!= 1好像缺少括号
标签: sql sql-server sql-server-2008 where where-clause