Home Forums SQL Server 2005 Development Ideas to accomplish desired results in my query RE: Ideas to accomplish desired results in my query

  • select

    item_location_view.qty_on_hand AS 'Qty on Hand',

    item_location_view.qty_allocated AS 'Qty Allocated',

    item_location_view.qty_backordered AS 'Qty Backordered'

    FROM dbo.inv_mast inv_mast, dbo.item_location_view item_location_view

    WHERE inv_mast.item_id = item_location_view.item_id AND ((item_location_view.qty_on_hand>=0) AND (item_location_view.qty_allocated>0) AND (item_location_view.qty_backordered>0))

    Just as a side note, in your programming practice try adopting the ANSI 92 standard of joining data sets. How would you represent a left join in the above? The '*' I am sure is way deprecated (though will still function for backward compatibility). Writing it this way will provide better readability and troubleshooting by commenting out filtration conditions :

    SELECT

    v.qty_on_hand AS 'Qty on Hand',

    v.qty_allocated AS 'Qty Allocated',

    v.qty_backordered AS 'Qty Backordered'

    FROM

    dbo.inv_mast inv_mast AS tbl

    INNER JOIN dbo.item_location_view AS v ON tbl.item_id=v.item_id

    WHERE

    (item_location_view.qty_on_hand>=0) AND

    (item_location_view.qty_allocated>0) AND

    (item_location_view.qty_backordered>0) AND

    1=1 /* <-- Just to help in your testing ; by commenting out any of the other line(s) in the

    where clause . It may help spot your issue. */

    ----------------------------------------------------