Click here to Skip to main content
15,895,084 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how would i change my stocktake to this:


1H011,TY06S-6000-NA,2
1H013,TB07H-6400-NA,4
1H013,TS95V-9400-NB,2
1H013,TY05H-6400-NA,5
1H021,TY06S-6000-NA,10
1H023,TY05H-6400-NA,1

from this:

1H013,TS95V-9400-NB,1
1H013,TY05H-6400-NA,3
1H013,TY05H-6400-NA,1
1H013,TB07H-6400-NA,2
1H021,TY06S-6000-NA,10
1H013,TS95V-9400-NB,S
1H013,TY05H-6400-NA,S
1H023,TY05H-6400-NA,S
1H013,TB07H-6400-NA,S
1H011,TY06S-6000-NA,S
1H013,TB07H-6400-NA,M
1H011,TY06S-6000-NA,M

as you can see it is sorted, same files are summed and the S's and M's =1.
need to do it with a script? and without a dictionary or master file?
Posted
Updated 26-Jul-11 13:21pm
v2

1 solution

You will need to do a SUM() in your selection, utilizing a GROUP BY to identify the breakup of the sums, a CASE statement to retrieve values, then use ORDER BY to sort them:
SQL
SELECT 
   Column1, 
   Column2, 
   SUM(
      CASE 
         WHEN column3 IN ('S', 'M') 
         THEN 1 
         ELSE CAST(column3 AS int)
      END
   ) AS SumOfColumn3 
FROM 
   sourceTable 
GROUP BY 
   Column1, 
   Column2 
ORDER BY 
   Column1, 
   Column2
 
Share this answer
 
Comments
victor.gatto 26-Jul-11 20:08pm    
can this be used in excel or? how do i run this, im excited cos ive been working so hard for a solution, and once i see how it works i will understand it
JOAT-MON 27-Jul-11 4:21am    
This is a sql command that needs to be run through a database connection like odbc or oledb. If your files are Excel, then you will need to establish a connection to them and run this query through the connection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900