sql server 2008 - SQL: Why is my query not returning values with a zero quantity? -


for reason, query returning 26 rows instead of 69 rows. omitting rows quantity zero. think there problem where clause. wrote obscene line because didn't know how else make query return values based on 1 of these 2 scenarios:

  1. user supplies quantity -> return rows quantity

  2. user not supply quantity -> return quantities

how can make query returns rows if user not supply value , maybe clean non-optimal where clause?

    declare @lp varchar(30) = '1250116'     declare @qty decimal      select          t.lp_num,         t.qty               isw_lptrans t               ((t.qty >-5000000000 , t.qty < 5000000000)) 

2nd attempt: didn't work either though, still returns 26 rows. edit: sorry! copied query above forgot change line fiddled with!

    declare @lp varchar(30) = '1250116'     declare @qty decimal = null;      select          t.lp_num,         t.qty               isw_lptrans t               (@qty null or t.qty = @qty) 

i not totally sure want clause because edits have changed meaning couple of times, can build case statement in clause , test conditions.

declare @lp varchar(30) = '1250116' declare @qty decimal  select      t.lp_num,     t.qty       isw_lptrans t     (case       when @qty null 1       when t.qty = @qty 1       else 0    end) = 1 

Comments