sql - Display data if Count(distinct) is 0 -
sql server 2008
sql query displays ip address if nowadays
select [ip_addr1_text], count(distinct [ip_addr1_text]) instances sem_computer, [dbo].[v_sem_computer] sem_computer.computer_id = [dbo].[v_sem_computer].computer_id , [ip_addr1_text] = '10.10.10.10' grouping [ip_addr1_text]
output
ip_addr1_text instances 10.10.10.10 1
if ip address count 0, output null.
how modify query instances outputs 0, next non-existant ip address, i.e.
select [ip_addr1_text], count(distinct [ip_addr1_text]) instances sem_computer, [dbo].[v_sem_computer] sem_computer.computer_id = [dbo].[v_sem_computer].computer_id , [ip_addr1_text] = '10.10.10.11' grouping [ip_addr1_text]
should output
ip_addr1_text instances 10.10.10.11 0
edit
screenshot of view
ip_addr1_text alias
column cast(case when ip_addr1 < 0 0xffffffff + ip_addr1 else ip_addr1 end / 256 / 256 / 256 & 0xff varchar) + '.' + cast(case when ip_addr1 < 0 0xffffffff + ip_addr1 else ip_addr1 end / 256 / 256 & 0xff varchar) + '.' + cast(case when ip_addr1 < 0 0xffffffff + ip_addr1 else ip_addr1 end / 256 & 0xff varchar) + '.' + cast(case when ip_addr1 < 0 0xffffffff + ip_addr1 else ip_addr1 end & 0xff varchar)
select [ip_addr1_text], coalesce(count(distinct [ip_addr1_text]),0) instances sem_computer left bring together [dbo].[v_sem_computer] on sem_computer.computer_id = [dbo].[v_sem_computer].computer_id , [ip_addr1_text] = '10.10.10.11' grouping [ip_addr1_text]
sql sql-server
No comments:
Post a Comment