THE SQL Server Blog Spot on the Web

Welcome to SQLblog.com - The SQL Server blog spot on the web Sign in | |
in Search

Browse by Tags

All Tags » Teaser   (RSS)
Showing page 1 of 3 (30 total posts)
  • SQL Teaser Count That Trancount

    Today's teaser is very simple First create this tableCREATE TABLE #Tran (TranCountDefault int DEFAULT (@@TranCount),TranCountPassedIn int)  As you can see that table has two columns, one column has a default of @@TRANCOUNT. Now run this piece of codeDECLARE @trancount intSELECT @trancount = @@TranCountINSERT #Tran (TranCountPassedIn) VALUES ...
    Posted to Denis Gobo (Weblog) by Denis Gobo on February 26, 2009
  • SQL Teaser: Missing FROM

    Take a look at this code, will the select return anything or not? Look at the subquery and notice that there is no FROM there.   USE tempdb GO CREATE TABLE TestQuery (TestID int) GO   SELECT * FROM information_schema.columns WHERE column_name =( SELECT column_name WHERE column_name = 'TestID')
    Posted to Denis Gobo (Weblog) by Denis Gobo on January 9, 2009
  • SQL Teaser: Where Clause Gone Wild

    Try to guess what this WHERE clause is supposed to do.   WHERE r.ApptId IS NULL AND r.DATE >= ISNULL(NULL , '1/1/1900') AND r.DATE < DATEADD(d , 1 , ISNULL(NULL , '1/1/3000')) AND --Filter on resource ( ( NULL IS NOT NULL AND r.DoctorResourceID IN ( NULL ) ) OR ( NULL IS NULL ) ) AND --Filter on facility ( ( NULL IS NOT ...
    Posted to Denis Gobo (Weblog) by Denis Gobo on July 25, 2008
  • SQL Teaser uniqueidentifier

    Create this tableCREATE TABLE #bla (SomeVal uniqueidentifier)INSERT #bla VALUES('D903D52D-DBFA-4904-9D95-F265152A391F')What do you think this will return? SELECT * FROM #blaWHERE SomeVal = 'D903D52D-DBFA-4904-9D95-F265152A391F12345678910'UNION ALLSELECT * FROM #blaWHERE SomeVal = 'D903D52D-DBFA-4904-9D95-F265152A391F1'Surprised? What about ...
    Posted to Denis Gobo (Weblog) by Denis Gobo on May 27, 2008
  • SQL Teaser: @@ROWCOUNT

    Without running this what do you think will be printed? SET ROWCOUNT 0DECLARE @ intSET @ =6IF @@ROWCOUNT = 1    PRINT 'yes'ELSE    PRINT 'no'PRINT @@rowcount
    Posted to Denis Gobo (Weblog) by Denis Gobo on May 8, 2008
  • SQL Teaser: Some Things Are Not What They Seem

    This one is a little sneaky, don’t send me hate mail for it. What does this return?   SELECT ISNUMERIC('+'),ISNUMERIC('–') Copy and paste it into QA/SSMS to verify  :-0    
    Posted to Denis Gobo (Weblog) by Denis Gobo on April 25, 2008
  • SQL Puzzle: Hours Stored As Integers

    You have a table where hours are stores as integers and you need to display it in weeks, days and hoursIf you have the following table CREATE TABLE #Hours (hours int)INSERT INTO #HoursSELECT 5 UNION ALLSELECT 55 UNION ALLSELECT 125 UNION ALLSELECT 1225 UNION ALLSELECT 555 UNION ALLSELECT 721 UNION ALLSELECT 719   The expected output is ...
    Posted to Denis Gobo (Weblog) by Denis Gobo on April 14, 2008
  • George's Division Teaser

    This teaser was posted by my friend George on Tek Tips and I am posting it here after I asked for his permission. the main reason I am posting it here is because I want to get some opinions from the experts. Take a look at these two queries If 1/0 = 10 And 1/1 = 0 Select 'True' As Query1 Else Select 'False' As Query1   If 1/0 = 10 And ...
    Posted to Denis Gobo (Weblog) by Denis Gobo on January 17, 2008
  • Yet Another Date Teaser

    It has been a while since my last teaser but here we go What do you think the following returns? SELECT CONVERT(datetime,'1/1/1') -CONVERT(datetime,1) + CONVERT(datetime,0)   How about this on SQL Server 2008 SELECT CONVERT(datetime2,'1/1/1'),CONVERT(datetime2,'01/01/01'),CONVERT(datetime2,'0001/01/01') Now run this on SQL Server ...
    Posted to Denis Gobo (Weblog) by Denis Gobo on January 10, 2008
  • SQL Teaser: LEN vs DATALENGTH

    This should trip up some people..... Without running this code what do you think will LEN and DATALENGTH return? DECLARE @i int SELECT @i =' 123456789 ' SELECT @i,LEN(@i),DATALENGTH(@i)
    Posted to Denis Gobo (Weblog) by Denis Gobo on December 12, 2007
1 2 3 Next >
Powered by Community Server (Commercial Edition), by Telligent Systems
  Privacy Statement