Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
Solved

update products.inwarehouse1 orderitems by the sum total of orderitems.is1q+orderitems.is2q+orderitems.is3q   (int)

Posted on 2010-09-20
Medium Priority
324 Views
select * from orderitems i
left join products p on p.productid=i.productid
where i.itemid>400000 order by i.itemid desc

I want to update products.ourinwarehouse1  (int)
by the sum total of
orderitems.is1q+orderitems.is2q+orderitems.is3q   (int)

but what if orderitems.is3q is null
0
Question by:rgb192
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
• 3
• 2
• 2
• +1

LVL 143

Expert Comment

ID: 33720403
this will do:
``````update p
set ourinwarehouse1  = ( select sum(is1q + is2q + is3q) from orderitems oi where oi.productid = p.productid and oi.itemid > 400000 )
from products p
``````
0

Author Comment

ID: 33720424
and if any of those values are null

do i need to do
isnull(is1q,0)
0

LVL 7

Expert Comment

ID: 33720431
something like:

update products.inwarehouse1 set qtycolumn = isnull(t2.qty, 0) + isnull(t3.qty, 0)
from products.inwarehouse1 t1
left outer join products.inwarehouse2 t2  on  t1.id = t2.id
left outer join products.inwarehouse3 t3  on  t2.id = t3.id
0

LVL 143

Expert Comment

ID: 33720443
yes
0

Author Comment

ID: 33720555
mquiroz
I dont understand

angelIII

I only want to update one oi.itemid to test
i tried

update p
set ourinwarehouse1  = ( select sum(oi.is1q + oi.is1n+p.ourinwarehouse1) from orderitems oi where oi.productid = p.productid and oi.itemid = 406438 )
from products p

Msg 8124, Level 16, State 1, Line 1
Multiple columns are specified in an aggregated expression containing an outer reference. If an expression being aggregated contains an outer reference, then that outer reference must be the only column referenced in the expression.
0

LVL 7

Expert Comment

ID: 33730221
you can use a join to update the table
0

LVL 12

Accepted Solution

jagssidurala earned 2000 total points
ID: 33732251
update      products
set            ourinwarehouse1  = A.total
(
select      Sum(Isnull(is1Q, 0) + Isnull(is2Q, 0) + Isnull(is3Q, 0)) as total,
Oi.productId
From      orderitems oi
where      oi.productid = p.productid
And            oi.itemid > 400000
Group
By            oi.ProductId
)A
Where productId = OI.ProductId
0

Author Closing Comment

ID: 33846218
thanks
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There are some very powerful Dynamic Management Views (DMV's) introduced with SQL 2005. The two in particular that we are going to discuss are sys.dm_db_index_usage_stats and sys.dm_db_index_operational_stats.   Recently, I was involved in a di…
In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses
Course of the Month10 days, 14 hours left to enroll