If you will forgive me a for a second question this week, I hadn't expected the need to do this but it turns out the MSFT Visio is very limited on linking external data so I need to compress some data that is in a table.
My singular table is created as such:
USE [VISIO]
GO
/****** Object: Table [dbo].[tbl_Raw_NIC_Imported] Script Date: 6/30/2015 2:47:18 PM ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[tbl_Raw_NIC_Imported](
[MACAddress] [varchar](50) NOT NULL,
[Host] [varchar](255) NOT NULL,
[IPAddress] [varchar](50) NOT NULL,
[IPSubnet] [varchar](50) NULL CONSTRAINT [DF_tbl_Raw_NIC_Imported_IPSubnet] DEFAULT (''),
[DefaultIPGateway] [varchar](50) NULL CONSTRAINT [DF_tbl_Raw_NIC_Imported_DefaultIPGateway] DEFAULT (''),
[DNSServer1] [varchar](50) NULL CONSTRAINT [DF_tbl_Raw_NIC_Imported_DNSServer1] DEFAULT (''),
[DNSServer2] [varchar](50) NULL CONSTRAINT [DF_tbl_Raw_NIC_Imported_DNSServer2] DEFAULT (''),
[WINSPrimary] [varchar](50) NULL CONSTRAINT [DF_tbl_Raw_NIC_Imported_WINSPrimary] DEFAULT (''),
[WINSSecondary] [varchar](50) NULL CONSTRAINT [DF_tbl_Raw_NIC_Imported_WINSSecondary] DEFAULT (''),
[InterfaceName] [varchar](255) NULL CONSTRAINT [DF_tbl_Raw_NIC_Imported_InterfaceName] DEFAULT (''),
CONSTRAINT [PK_IPAddress1] PRIMARY KEY CLUSTERED
(
[IPAddress] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO
SET ANSI_PADDING OFF
GO
The table is populated with data similar to this sample data which is useful to highlight my question:
MACAddress,Host,IPAddress,IPSubnet,DefaultIPGateway,DNSServer1, DNSServer2,WINSPrimary,WINSSecondary,InterfaceName
00:50:56:B6:00:92,svr1.my.local,10.191.240.112,255.255.255.0,10.194.240.2,10.10.100.202,10.10.100.200,,, Intel(R) PRO/1000 MT Network Connection
00:50:56:B6:00:92,svr1.my.local,10.191.240.114,255.255.255.0,10.194.240.2,10.10.100.202,10.10.100.200,,,Intel(R) PRO/1000 MT Network Connection
00:50:56:B6:00:92,svr1.my.local,10.191.240.115,255.255.255.0,10.194.240.2,10.10.100.202,10.10.100.200,,,Intel(R) PRO/1000 MT Network Connection
00:50:56:B6:00:92,svr1.my.local,fe80::ed77:187d:80af:5e4d,64,10.194.240.2,10.10.100.202,10.10.100.200,,,Intel(R) PRO/1000 MT Network Connection
00:50:56:B6:00:95,svr1.my.local,192.168.0.3,255.255.255.0,192.168.0.1,,,,,Intel(R) PRO/1000 MT Network Connection #2
EE:50:56:B6:00:95,svr2.my.local,192.168.0.4,255.255.255.0,192.168.0.1,,,,,Intel(R) PRO/1000 MT Network Connection
What I would like to accomplish is to have a view that compresses rows that have multiple IP addresses assigned to a given adapter. I would also like to exclude the IPv6 addresses. Based off of the sample data, the resulting view would have rows that look like this:
MACAddress,Host,IPAddress,IPSubnet,DefaultIPGateway,DNSServer1, DNSServer2,WINSPrimary,WINSSecondary,InterfaceName
00:50:56:B6:00:92,svr1.my.local,10.191.240.112 | 114 | 115,255.255.255.0,10.194.240.2,10.10.100.202,10.10.100.200,,, Intel(R) PRO/1000 MT Network Connection
00:50:56:B6:00:95,svr1.my.local,192.168.0.3,255.255.255.0,192.168.0.1,,,,,Intel(R) PRO/1000 MT Network Connection #2
EE:50:56:B6:00:95,svr2.my.local,192.168.0.4,255.255.255.0,192.168.0.1,,,,,Intel(R) PRO/1000 MT Network Connection
Where the first 3 records are collapsed into one and the IPAddress shows the 3 IPs. The fourth record isn't present and the fifth is. I have see lots of examples of concat and XML usage but they don't seem to fit the need or I haven't been able to adapt them.
This came the closest to anything and, oh, ARG, this won't work in a view anyway it seems even though it produces the output that I need.
SELECT
Source.[MACAddress],
UPPER(Source.[Host]),
STUFF((SELECT ' | ' + Changed.[IPAddress]
FROM [VISIO].[dbo].[tbl_Raw_NIC_Imported] Changed
WHERE (((Changed.[MACAddress] = Source.[MACAddress]) AND (Changed.[Host] = Source.[Host])) AND (Changed.[IPAddress] NOT LIKE '%:%'))
FOR XML PATH('')), 2, 1, '') [COMBINED IP],
Source.[IPSubnet],
Source.[DefaultIPGateway],
Source.[DNSServer1],
Source.[DNSServer2],
Source.[WINSPrimary],
Source.[WINSSecondary],
Source.[InterfaceName]
FROM [VISIO].[dbo].[tbl_Raw_NIC_Imported] Source
WHERE Source.[IPSubnet] <>'64'
GROUP BY Source.[MACAddress], Source.[Host], Source.[IPSubnet], Source.[DefaultIPGateway],
Source.[DNSServer1], Source.[DNSServer2], Source.[WINSPrimary], Source.[WINSSecondary], Source.[InterfaceName]
ORDER BY 1
Any insight on how to do this same thing in a view would be much appreciated.
Thanks,
Casey