有关SELECT的一个最简单的问题
我想要在 select 的结果为空的时候,就换一个结果返回:
@UserIP int
AS
if ISNULL(SELECT CountryID from Cities_CountriesIP where @UserIP>StartIP AND @UserIP<EndIP)
BEGIN
SELECT CountryID from Cities_CountriesIP where @UserIP>StartIP AND @UserIP<EndIP
END
ELSE
BEGIN
SELECT CountryID from Cities_CountriesIP where 100663297>StartIP AND 100663297<EndIP
END
谁知ISNULL这一句出现错误,请问如何判断SELECT的结果为空的情况?
------解决方案--------------------
SQL code
SELECT CountryID from Cities_CountriesIP where @UserIP>StartIP AND @UserIP<EndIP
IF @@ROWCOUNT = 0
BEGIN
SELECT CountryID from Cities_CountriesIP where 100663297>StartIP AND 100663297<EndIP
END