Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


ProductId Search


ProductId Search

Author
Message
2Tall
2Tall
Say Hey Kid
Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)

Group: General Forum Members
Points: 702 Visits: 1203
I would like my query to return a unique value for the ProductId + count stock so I get a single value for available stock.

Query:

SELECT DISTINCT ProductId,ProductDescription,Quantity,QuantityOutstanding,StandardPrice
FROM Products
INNER JOIN dbo.Inventory ON dbo.Inventory.Product= dbo.Products.Product
WHERE QuantityOutstanding >0



Example Output:
ProductId ProductDescription Quantity QuantityOutstanding
0-0125223214 MY PRODUCT 1 1
0-0125223214 MY PRODUCT 3 3
0-0125223214 MY PRODUCT 4 4
0-0125223214 MY PRODUCT 10 10

Can anyone assist?
Many Thanks,
Phil.

-------------------------------------------------------------------------------------
A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

Tommy Cooper

Mahesh Bote
Mahesh Bote
Ten Centuries
Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)Ten Centuries (1.1K reputation)

Group: General Forum Members
Points: 1104 Visits: 1274
If I am not wrong, do you want something like this ...?

SELECT    ProductId
,ProductDescription
,Sum(Quantity)
,Sum(QuantityOutstanding)
,StandardPrice
FROM Products INNER JOIN dbo.Inventory
ON dbo.Inventory.Product = dbo.Products.Product
WHERE QuantityOutstanding >0
GROUP BY ProductId
,ProductDescription
,StandardPrice



I think you must not in need of stock count but Total stock. Can you spread some more light on this with desired o/p so that we can give you better solution.

Mahesh


MH-09-AM-8694
2Tall
2Tall
Say Hey Kid
Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)Say Hey Kid (702 reputation)

Group: General Forum Members
Points: 702 Visits: 1203
Mahesh thanks for your time, I managed to resolve (well it looks OK). My query looks as follows:


SELECT DISTINCT ProductId,ProductDescription,ISNULL(CONVERT(VARCHAR,SUM(QuantityOutstanding)),'0')AS Quantity,StandardPrice

FROM Products

LEFT JOIN dbo.Inventory ON dbo.Inventory.Product= dbo.Products.Product

GROUP BY Products.ProductId, Products.ProductDescription, Products.StandardPrice



The Products table contains 1000's of records, the Inventory table less than a thousand so the query returned a load of NULL values. The above substitutes NULL with 0.

If anyone can see a potential problem with this approach then please advise.
Thanks,
Phil.

-------------------------------------------------------------------------------------
A neutron walks into a bar. "I'd like a beer" he says. The bartender promptly serves up a beer. "How much will that be?" asks the neutron. "For you?" replies the bartender, "no charge."

Two hydrogen atoms walk into a bar. One says, 'I think I've lost an electron.' The other says 'Are you sure?' The first says, 'Yes, I'm positive... '

Tommy Cooper

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search