I have a table named dbo.WebsiteIP
having two columns IPAddress
, SiteName
, and I am doing a bulk insert the values to the this table which look like below
IPAddress SiteName
192.168.30.6 website1.domain.com
192.168.30.6 website2.domain.com
192.168.30.7 website3.domain.com
192.168.30.7 website4.domain.com
192.168.30.7 website5.domain.com
192.168.30.7 website6.domain.com
192.168.30.7 website7.domain.com
192.168.30.8 website8.domain.com
192.168.30.8 website9.domain.com
192.168.30.8 website10.domain.com
192.168.30.8 website11.domain.com
192.168.30.9 website12.domain.com
192.168.30.8 website13.domain.com
192.168.30.8 website14.domain.com
192.168.30.24 website15.domain.com
192.168.30.8 website16.domain.com
192.168.30.8 website17.domain.com
I want to do a distinct query for the IP Address and combine the SiteName
like below
IPAddress WebsiteName
192.168.30.6 website1, website2,
192.168.30.7 website3, website4, website5, website6, website7
192.168.30.8 website8, website9, website10, website11, website13, website14
192.168.30.9 website12
192.168.30.24 website15
I can able to combine the IPAddress
using the below query but how to combine the appropriate Sitename
to the IP Address.
Update Table1
Set IP= (Select IPAddress + ',' + ' '
From dbo.WebsiteIP
GROUP BY IPAddress FOR XML PATH(''))
GO