Getting Started with ASP.NET MVC - Part 6: ASP.NET MVC and Entity Framework
First Time? You can support us by signing up. It takes only 5 seconds. Click here to sign up. If you already have an account, click here to login.


Upload Image Close it
Select File

Browse by Tags · View All
sql_server 217
t-sql 211
tsql 113
sqlserver 94
BRH 78
#SQLServer 65
#TSQL 55
SQL Server 32
function 11
SSMS 9

Archive · View All
August 2007 17
August 2010 8
June 2011 7
November 2007 7
November 2011 6
August 2011 6
October 2011 6
July 2011 6
September 2011 6
December 2011 6

Madhivanan's TSQL Blog

Fun in TSQL - TSQL from TSQL

Dec 5 2011 3:57AM by Madhivanan   

This is just for Fun. The following code is unformatted, unclear and may be confusing. But curious to know the result? Set the result mode of the query window to Text . While you are in Query Window press CONTROL+T and run the following code and see what it returns.

                                                                     
set nocount on select case no when 1 then col when 2 then stuff(stuff(stuff(stuff(col,1,cast(4e1/5 as int),replicate(' ',cast(4e1/5 as int))),cast(2e1-1 as int),3,replicate(' ',3)),cast(sqrt(12+11e2)/3 as int)*3,
5,replicate(' ',5)),cast(5e1-3 as int),cast(2e1-4 as int),replicate(' ',3)) when 3 then stuff(stuff(stuff(stuff(col,1,cast(4e1/5 as int),replicate(' ',cast(4e1/5 as int))),cast(2e1-1 as int),3,replicate(' ',3)),cast(sqrt(12+11e2)/3 as int)*3,4,replicate(' ',4)),cast(5e1-2 as int),cast(2e1-5 as int),replicate(' ',2)) when 4 then stuff(
stuff(stuff(stuff(stuff(col,1,cast(4e1/5 as int),replicate(' ',cast(4e1/5 as int))),cast(2e1-1 as int),3,replicate(' ',3)),28,cast(4e1/5 as int),replicate(' ',cast(4e1/5 as int))),cast(POWER(ISNULL(null,4),3)-3e0-(7*3) as int),3,replicate(' ',3)),cast(5e1-2 as int),cast(2e1-5 as int),replicate(' ',2)
)when 5 then stuff(stuff(stuff(stuff(stuff(col,1,cast(4e1/5 as int),replicate(' ',cast(4e1/5 as int))),cast(2e1-1 as int),3,replicate(' ',3)),28,cast(4e1/5 as int),replicate(' ',cast(4e1/5 as int))),cast(POWER(ISNULL(null,4),3)-3e0-(7*3) as int),3,replicate(' ',3)),cast(5e1-1 as int),cast(2e1-6 as int),replicate(' '
,1))when 6 then stuff(stuff(stuff(stuff(stuff(col,1,cast(sqrt(12+11e2)/3 as int),replicate(' ',cast(sqrt(12+11e2)/3 as int))),cast(2e1-4 as int),6,replicate(' ',6)),cast(sqrt(12+11e2)/3 as int)*3,3,replicate(' ',3)),cast(POWER(ISNULL(null,4),3)-3e0-(7*3) as int),3,replicate(' ',3)),cast(5e1-1 as int),cast(2e1-6 as int),
replicate(' ',1))when 7 then stuff(stuff(stuff(stuff(stuff(col,1,cast(sqrt(12+11e2)/3 as int),replicate(' ',cast(sqrt(12+11e2)/3 as int))),cast(2e1-4 as int),6,replicate(' ',6)),cast(sqrt(12+11e2)/3 as int)*3,3,replicate(' ',3)),cast(POWER(ISNULL(null,4),3)-3e0-(7*3) as int),3,replicate(
' ',3)),cast(5e1-2 as int),cast(2e1-5 as int),replicate(' ',2))when 8 then stuff(stuff(stuff(stuff(stuff(col,1,cast(sqrt(12+11e2)/3 as int),replicate(' ',cast(sqrt(12+11e2)/3 as int))),cast(2e1-4 as int),10,replicate(' ',10)),cast(sqrt(12+11e2)/3 as int)*3,4,replicate(' ',4)),cast(5e1-3 as int),3,replicate(' ',3)),cast(5e1+8 as int),cast(2e1-7 as int),REPLICATE(' '
,cast(2e1-7 as int)))when 9 then stuff(stuff(stuff(stuff(col,1,cast(sqrt(12+11e2)/3 as int),replicate(' ',cast(sqrt(12+11e2)/3 as int))),cast(2e1-4 as int),10,replicate(' ',10)),cast(sqrt(12+11e2)/3 as int)*3,6,replicate(' ',6)),cast(5e1-6 as int),6,replicate(' ',6))when 10 then stuff(stuff(stuff(stuff(col,1,cast(sqrt(12
+11e2)/3 as int),replicate(' ',cast(sqrt(12+11e2)/3 as int))),cast(2e1-4 as int),6,replicate(' ',6)),cast(sqrt(12+11e2)/3 as int)*3,6,replicate(' ',6)),cast(5e1-6 as int),6,replicate(' ',6))	when 11 then stuff(stuff(stuff(stuff(col,1,cast(sqrt(12+11e2)/3 as int),replicate(' ',cast(sqrt(12+11e2)/3 as int))
),cast(2e1-4 as int),6,replicate(' ',6)),cast(sqrt(12+11e2)/3 as int)*3,7,replicate(' ',7)),cast(5e1-5 as int),5,replicate(' ',5))when 12 then col end from(select no,replicate(char(42),ceiling(15e3/215)) as col	from (select top (cast(3e2/25 AS int)) row_number() over (order by name) as no from sys.sysobjects )as t 
) as t

Tags: t-sql, sql_server, sqlserver, tsql, fun, #SQL SERVER,


Madhivanan
4 · 39% · 8850
12
 
0
Lifesaver
 
0
Refreshed
 
0
Learned
 
0
Incorrect



Submit

4  Comments  

  • Very nice :)

    commented on Dec 5 2011 6:36AM  .  Report Abuse This post is not formatted correctly
    Jan Novak
    500 · 0% · 44
  • Good one..

    commented on Dec 5 2011 10:01PM  .  Report Abuse This post is not formatted correctly
    Hardik Doshi
    23 · 7% · 1647
  • it's really cool.......

    commented on Dec 11 2011 11:18PM  .  Report Abuse This post is not formatted correctly
    Shivendra Kumar Yadav
    108 · 2% · 418
  • Hi Madhivanan,

    Its vry interesting............

    But i want to know the logic behind this, can u help me to come out.

    commented on Apr 30 2012 5:26AM  .  Report Abuse This post is not formatted correctly
    balakrishna141
    2307 · 0% · 2

Your Comment


Sign Up or Login to post a comment.

"Fun in TSQL - TSQL from TSQL" rated 5 out of 5 by 12 readers
Fun in TSQL - TSQL from TSQL , 5.0 out of 5 based on 12 ratings
    Copyright © Beyondrelational.com Contact us      Privacy Policy      Terms of use      Report Abuse      Advertising