Puzzles – SQLSERVERLEARNER https://sqlserverlearner.com LEARN SQL SERVER ONLINE Fri, 01 Jul 2011 11:26:34 +0000 en-US hourly 1 https://wordpress.org/?v=6.5.2 PUZZLE – 2 – Queries https://sqlserverlearner.com/2011/07/01/puzzle2/ https://sqlserverlearner.com/2011/07/01/puzzle2/#respond Fri, 01 Jul 2011 11:26:34 +0000 https://sqlserverlearner.azurewebsites.net/2011/07/01/puzzle2/ What is the output of each statement in the below query:

[sql]
SELECT 1 WHERE NULL = NULL

SELECT COUNT(10)

SELECT COUNT(C1) FROM (SELECT ‘A’ AS C1 UNION ALL SELECT ‘B’ UNION ALL SELECT NULL) T

SELECT NULL
UNION
SELECT NULL
[/sql]

Please provide your comments.

]]>
https://sqlserverlearner.com/2011/07/01/puzzle2/feed/ 0
PUZZLE1 – What is the output of the below query NEWID https://sqlserverlearner.com/2011/06/30/puzzle1-what-is-the-output-of-the-below-query-newid/ https://sqlserverlearner.com/2011/06/30/puzzle1-what-is-the-output-of-the-below-query-newid/#respond Thu, 30 Jun 2011 08:19:05 +0000 https://sqlserverlearner.azurewebsites.net/2011/06/30/puzzle1-what-is-the-output-of-the-below-query-newid/ What is the output of the following query:
DECLARE @TEMPNEWID TABLE (iden int identity(1,1),COL1 int,COL2 UNIQUEIDENTIFIER)

INSERT INTO @TEMPNEWID(COL1,COL2)
SELECT 1,NEWID()
UNION
SELECT 2,NEWID()
UNION
SELECT 3,NEWID()
UNION
SELECT 4,NEWID()
UNION
SELECT 5,NEWID()
UNION
SELECT 6,NEWID()
UNION
SELECT 7,NEWID()
UNION
SELECT 8,NEWID()
UNION
SELECT 9,NEWID()
UNION
SELECT 10,NEWID()
UNION
SELECT 11,NEWID()
UNION
SELECT 12,NEWID()

DELETE T FROM
@tempnewid AS T
INNER JOIN (SELECT TOP 3 iden FROM
@tempnewid ORDER BY NEWID() ) as T1
ON T.iden = T1.iden

SELECT COUNT(*) FROM @tempnewid

How many records will be deleted from table variable @tempnewid?
What will be the output of count(*)?

]]>
https://sqlserverlearner.com/2011/06/30/puzzle1-what-is-the-output-of-the-below-query-newid/feed/ 0