same query... just want negative value

this query finds productid
I want to know the count of each productid
and use the productid count to
update p.ourinwarehouse = productid count


select p.productid from orderitems2 i
inner join orders2 o on o.orderid = i.orderid
right join payments y on o.orderid = y.orderid
inner join products2 p on i.productid = p.productid
where o.statusid in (9,10,90,180,260)
order by p.productid desc


150293
150293
150292
150285
150284
150283
150283
150283
150283
150283
150283
150280
150280
150277
150273
150268
150265
150264
150264
150264
150264
150264
150264
150264
150264
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150263
150258






Update p
set ourinwarehouse = P_Cnt.prod_Cnt
from products2 p join (
select p2.productid, count(*) prod_Cnt from orderitems2 i
inner join orders2 o on o.orderid = i.orderid
right join payments y on o.orderid = y.orderid
inner join products2 p2 on i.productid = p2.productid
where o.statusid in (9,10,90,180,260)
group by p2.productid) P_Cnt on p.productid = P_Cnt.productid

works


but I want p.ourinwarehouse to be negative
same number
just with a negative sign in front of it



and this must be done by changing the query....
only using one query
LVL 1
rgb192Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JR2003Commented:
Just a a minus sign infront of the count
Update p
set ourinwarehouse = P_Cnt.prod_Cnt
from products2 p join (
select p2.productid, -count(*) prod_Cnt from orderitems2 i
inner join orders2 o on o.orderid = i.orderid
right join payments y on o.orderid = y.orderid
inner join products2 p2 on i.productid = p2.productid
where o.statusid in (9,10,90,180,260)
group by p2.productid) P_Cnt on p.productid = P_Cnt.productid

0
Raja Jegan RSQL Server DBA & Architect, EE Solution GuideCommented:
Try this:
Update p
set ourinwarehouse = -1 * P_Cnt.prod_Cnt
from products2 p join (
select p2.productid, count(*) prod_Cnt from orderitems2 i
inner join orders2 o on o.orderid = i.orderid
right join payments y on o.orderid = y.orderid
inner join products2 p2 on i.productid = p2.productid
where o.statusid in (9,10,90,180,260)
group by p2.productid) P_Cnt on p.productid = P_Cnt.productid

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JR2003Commented:
I think just the minus sign will do the trick:
 

Update p 
set ourinwarehouse = -P_Cnt.prod_Cnt 
....

Open in new window

0
rgb192Author Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server 2005

From novice to tech pro — start learning today.