I have SQL code (abridged)
SELECT replace(replace(replace(replace(dbo.IDENTITY_MAP.Name,'My Company\',''),'-VLAN2',''),'.VLAN2\',''),'.Instr\','') as Site,
Count (CASE
WHEN dbo.SEM_AGENT.AGENT_VERSION LIKE '11.%'
AND dbo.SEM_COMPUTER.OPERATION_SYSTEM LIKE 'Windows%' THEN 1
............
Group by replace(replace(replace(replace(dbo.IDENTITY_MAP.Name,'My Company\',''),'-VLAN2',''),'.VLAN2\',''),'.Instr\','')
Order by Site
My output looks like this
But I wish for it to look like this, where all row values corresponding to Site '7' are summed, etc
I believe Regex would help, because this
^\w+(?:\s+\w+)?\\|[A-Z].*$
would isolate the number after the '\'
But when I attempt to do a replace statement with regex
SELECT replace(replace(replace(replace(replace(dbo.IDENTITY_MAP.Name,'My Company\',''),'-VLAN2',''),'.VLAN2\',''),'.Instr\',''), '^\w+(?:\s+\w+)?\\|[A-Z].*$') as Site,
I get error
The replace function requires 3 argument(s).
Please guide
Another Update
I tried this MS SQL code (abridged)
SELECT patindex('^\w+(?:\s+\w+)?\\|[A-Z].*$',replace(replace(replace(replace(dbo.IDENTITY_MAP.Name,'My Company\',''),'-VLAN2',''),'.VLAN2\',''),'.Instr\','')) as Site,
Count (CASE
WHEN dbo.SEM_AGENT.AGENT_VERSION LIKE '11.%'
AND dbo.SEM_COMPUTER.OPERATION_SYSTEM LIKE 'Windows%' THEN 1
END) AS 'Windows-SEP-11',
......
Group by patindex('^\w+(?:\s+\w+)?\\|[A-Z].*$',replace(replace(replace(replace(dbo.IDENTITY_MAP.Name,'My Company\',''),'-VLAN2',''),'.VLAN2\',''),'.Instr\',''))
Order by Site
And this is output