如何检查SELECT

时间:2015-11-11 16:13:05

标签: sql tsql

我有我在下面运行的查询。如果CMS中的值没有带有的完全限定域名。在其中我的查询失败。在继续之前如何检查我的SUBSTRING是否为真?

SELECT 
    DISTINCT SUBSTRING(s.server_name, 1, CHARINDEX('.', s.server_name)-1) AS [ServerName]
FROM
    msdb.dbo.sysmanagement_shared_server_groups_internal g 
INNER JOIN 
    msdb.dbo.sysmanagement_shared_registered_servers_internal s
        ON g.server_group_id = s.server_group_id
ORDER BY 
    ServerName

1 个答案:

答案 0 :(得分:2)

使用where子句检查server_name是否包含至少1 .

SELECT DISTINCT SUBSTRING(s.server_name, 1, CHARINDEX('.', s.server_name)-1) AS [ServerName]
FROM  msdb.dbo.sysmanagement_shared_server_groups_internal g 
INNER JOIN msdb.dbo.sysmanagement_shared_registered_servers_internal s
ON g.server_group_id = s.server_group_id
where  CHARINDEX('.', s.server_name) > 0
ORDER BY ServerName