Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql statement (where clause)

Status
Not open for further replies.

dynodave

Programmer
Sep 23, 2002
11
GB
I have this sql statement and i need to include Rec_Qty and Del_Qty in the where clause how is this possible please

SELECT depot, loadno, partno, quantity,
case when type = 'S' THEN
quantity * -1
ELSE
0.00
END Rec_Qty,
CASE WHEN type <> 'S' THEN
quantity
ELSE
0.00
END Del_Qty
FROM dbo.moves
WHERE depot BETWEEN @DepFrom and @DepTo
AND loadno BETWEEN @LoadFrom and @LoadTo
 
You can use a derived table, e.g.

select * from (
SELECT depot, loadno, partno, quantity,
case when type = 'S' THEN
quantity * -1
ELSE
0.00
END Rec_Qty,
CASE WHEN type <> 'S' THEN
quantity
ELSE
0.00
END Del_Qty
FROM dbo.moves
WHERE depot BETWEEN @DepFrom and @DepTo
AND loadno BETWEEN @LoadFrom and @LoadTo
) dt
where req_qty = -4711
and del_qty = 4711
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top