July 31, 2013 at 5:22 am
I'm quite new with sql and hope someone can help me with the following issue;
I have the following result after running my report;
item_numloc Sum sls-qty-12mnthSum sls-qty-6mnthSum sls-qty-3mnth
25025345NON-CONFORMITY 163 83 35
XF030304 163 83 35
25025346NON-CONFORMITY 83 30 1
XK010102 83 30 1
I would like to count the locations by item and divide the sum 'sls qty 12 -6 and 3 months' with the total location, in this case the result should be something like;
item_numloc Sum sls-qty-12mnthSum sls-qty-6mnthSum sls-qty-3mnth
25025345NON-CONFORMITY 81.5 41.5 17.5
XF030304 81.5 41.5 17.5
25025346NON-CONFORMITY 41.5 15 0.5
XK010102 41.5 15 0.5
as you can see the sum sls qty's months gives me the grand total for both location while I would like to split this between the two locations.
I'm not referring to qty by location but total locations.
When I add the COUNT function to the view in order to count the location by item I get the error message all the other tables should be in aggregate or group mode.
I'm working on a 2008 R2 SQL and the queries for this report are coming from 3 different views.
I hope my issue is understandable
does some one knows how to make a Count of the locations by item for a complete list of more than 7000 items than can be located in more than one location in SQL?
😉
thank you very much in advance for any help in the good direction,
July 31, 2013 at 7:45 am
Hi and welcome to the forums. In order to help we will need a few things:
1. Sample DDL in the form of CREATE TABLE statements
2. Sample data in the form of INSERT INTO statements
3. Expected results based on the sample data
Please take a few minutes and read the first article in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply