I have a table below
Program FileCount
B1 1
A1;B2 2
A2;B3 1
A3;C1;B4 1
A3;C2;D1;B5;B6 3
C3;D2;B7 1
B8;B9 2
B8;B9 2
I'm only interested in program B and I would like to take all program B
Program FileCount
B1 1
B2 2
B3 1
B4 1
B5 3
B6 3
B7 1
B8 4
B9 4
Please note :
- I'm using Microsoft SQL Server 2012
- the name for program B are not uniform having 2 digits only but vary (example, B1233456, B123)
I have used the syntax below however it doesn't give what I need.
SELECT
distinct CASE WHEN PATINDEX('%B%', Program)>0 THEN SUBSTRING(Program, PATINDEX('%B%', Program), 50) ELSE '' END as Program,
sum(cast (Filecount as integer)) as FileCount
FROM dbo.Database1
where Program like '%B%'
group by Program
Thank you very much guys for your help.
Kind regards,
Adhi