I will try again, sorry.
This is what I get |
|
|
|
|
Prefix |
Client |
BCC Matters |
LCC Matters |
BA Matters |
ACC4 |
Accelerated Education Enterprises (Pty) Ltd |
3 |
0 |
0 |
ACC4 |
Accelerated Education Enterprises (Pty) Ltd_Inc |
0 |
1 |
0 |
ATH10 |
Atholton Primary School |
2 |
0 |
0 |
ATH10 |
Atholton Primary School_BA |
0 |
0 |
19 |
ATH10 |
Atholton Primary School_Inc |
0 |
1 |
0 |
ATT2 |
Dr Attwood - Smith_BA |
0 |
0 |
1 |
BER18 |
Berea West Pre Primary School |
3 |
0 |
0 |
BER18 |
Berea West Pre Primary School _BA |
0 |
0 |
4 |
BER18 |
Berea West Pre Primary School _Inc |
0 |
1 |
0 |
|
|
|
|
|
This is what I am looking for |
|
|
|
|
Prefix |
Client |
BCC Matters |
LCC Matters |
BA Matters |
ACC4 |
Accelerated Education Enterprises (Pty) Ltd |
3 |
1 |
0 |
ATH10 |
Atholton Primary School |
2 |
1 |
19 |
ATT2 |
Dr Attwood - Smith_BA |
0 |
0 |
1 |
BER18 |
Berea West Pre Primary School |
3 |
1 |
4 |
This is the data and scripts:
Use [tempdb];
Go
IF OBJECT_ID('tempdb..#TempFile') IS NOT NULL DROP TABLE #TempFile;
Go
CREATE TABLE [dbo].[#TempFile](
[Prefix] nvarchar NOT NULL,
[Client] nvarchar NOT NULL,
[ID] nvarchar NOT NULL
);
Go
INSERT INTO #TempFile VALUES ('ACC4','Accelerated Education Enterprises (Pty) Ltd_Inc','ACC4-0072');
INSERT INTO #TempFile VALUES ('BER18','Berea West Pre Primary School ','BER18-0033');
INSERT INTO #TempFile VALUES ('BER18','Berea West Pre Primary School _BA','BER18-0021');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0102');
INSERT INTO #TempFile VALUES ('ACC4','Accelerated Education Enterprises (Pty) Ltd','ACC4-0081');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0146');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0149');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0170');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0171');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0143');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0065');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0077');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0153');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0156');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0169');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0175');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School','ATH10-0167');
INSERT INTO #TempFile VALUES ('BER18','Berea West Pre Primary School _BA','BER18-0029');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_Inc','ATH10-0154');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0123');
INSERT INTO #TempFile VALUES ('ATT2','Dr Attwood - Smith_BA','ATT2-0034');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0165');
INSERT INTO #TempFile VALUES ('BER18','Berea West Pre Primary School _BA','BER18-0025');
INSERT INTO #TempFile VALUES ('ACC4','Accelerated Education Enterprises (Pty) Ltd','ACC4-0089');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0145');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0147');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School','ATH10-0174');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0126');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0168');
INSERT INTO #TempFile VALUES ('BER18','Berea West Pre Primary School _Inc','BER18-0031');
INSERT INTO #TempFile VALUES ('BER18','Berea West Pre Primary School ','BER18-0032');
INSERT INTO #TempFile VALUES ('ATH10','Atholton Primary School_BA','ATH10-0150');
INSERT INTO #TempFile VALUES ('BER18','Berea West Pre Primary School _BA','BER18-0022');
INSERT INTO #TempFile VALUES ('ACC4','Accelerated Education Enterprises (Pty) Ltd','ACC4-0098');
INSERT INTO #TempFile VALUES ('BER18','Berea West Pre Primary School ','BER18-0034');
Go
Select Prefix As [Prefix]
, Client As [Client]
, Case When Client Not Like '%[]INC' And Client Not Like '%[]BA' Then Count(ID) Else 0 End [BCC Matters]
, Case When Client Like '%[]INC' Then Count(ID) Else 0 End [LCC Matters]
, Case When Client Like '%[]BA' Then Count(ID) Else 0 End [BA Matters]
From #TempFile
Group By Prefix, Client
Order By Prefix;
IF OBJECT_ID('tempdb..#TempFile') IS NOT NULL DROP TABLE #TempFile;
Please help and thanks for the advice.