I am trying to write sp to update a table with the results of itself having trouble getting it to work without using a temp table.
Anybody have some ideas.
The following works I would like to avoid using temp table if possible.
Anybody have some ideas.
The following works I would like to avoid using temp table if possible.
Code:
SELECT CASE i.user_def_fld_4
WHEN '' THEN convert(int, (o.qty_to_ship/i.cube_qty_per) )
WHEN i.cube_qty_per THEN convert(int, (o.qty_to_ship/i.cube_qty_per))
ELSE convert(int,(o.qty_to_ship/i.user_def_fld_4) )
END as cc, o.ord_no
INTO dbo.#cartoncount
FROM dbo.oeordlin_sql o INNER JOIN imitmidx_sql i
ON o.item_no = i.item_no
WHERE o.qty_to_ship > 0 and ord_type = 'O'
GROUP BY o.ord_no, CASE i.user_def_fld_4
WHEN '' THEN convert( int, (o.qty_to_ship/i.cube_qty_per ))
WHEN i.cube_qty_per
THEN convert(int,(o.qty_to_ship/i.cube_qty_per))
ELSE convert(int,(o.qty_to_ship/i.user_def_fld_4))
END
UPDATE o
SET o.user_def_fld_2 = c.cc
FROM oeordlin_sql o
INNER JOIN #cartoncount c on o.ord_no = c.ord_no