In a script, I wrote a SELECT and forgot to add the FROM. I was scratching my head as to why the “COUNT(*)” kept returning 1. Apparently it will always return 1 if there is no FROM.
Test Script:
SELECT COUNT(*) AS 'Ct* - Initial'Results:
GO
SET NOCOUNT ON
GO
SELECT COUNT(*) AS 'Ct* - Initial'
SELECT @@SERVERNAME AS '@@SERVERNAME'
SELECT COUNT(*) AS 'Ct* - @@SERVERNAME'
SELECT TOP 10 [name] FROM sys.databases
SELECT COUNT(*) AS 'Ct* - sys.databases'
Ct* - Initial
-------------
1
(1 row(s) affected)
Ct* - Initial
-------------
1
@@SERVERNAME
---------
[snip]
Ct* - @@SERVERNAME
------------------
1
name
---------
master
tempdb
model
msdb
...
Ct* - sys.databases
-------------------
1
No comments:
Post a Comment