Search This Blog

Art Of SQL Part 2

This is my second Post on Art Of SQL. As i mentioned on my firstpost, in order to run this, you should press 'Ctrl+T'

Here it is ....








declare @tab table ( i int identity, j varchar(100))
declare @comma char(1)
set @Comma = ''''

SET NOCOUNT ON
INSERT INTO @tab SELECT REPLICATE('*',9)
UPDATE @tab
SET j = j+'.'+ CAST(0x2D2D2C5F as varchar)

INSERT INTO @tab
SElECT REPLICATE('*',8)+'['
UPDATE @Tab
SET j = j+@Comma
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET j = J + REPLICATE('*',4)+@Comma
WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J = J+ cast(0x5C2E as varchar)
WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J = J+REPLICATE (@Comma ,2)
WHERE i = SCOPE_IDENTITY()

INSERT INTO @tab
SELECT REPLICATE('*',9)+'\'+REPLICATE('*',7)
UPDATE @Tab
SET J = j + '`'
WHERE i = SCOPE_IDENTITY()
--SELECT REPLICATE('*',9)+'\'+REPLICATE('*',7)
UPDATE @Tab
SET J = j + @Comma+@Comma+'|'
WHERE i = SCOPE_IDENTITY()


INSERT INTO @tab
SELECT J
FROM @Tab
WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J = REPLACE ( j,'|',',]')
WHERE i = SCOPE_IDENTITY()

UPDATE @Tab
SET J = REPLACE ( j,'\','|')
WHERE i = SCOPE_IDENTITY()


UPDATE @Tab
SET J = REPLACE ( j,@comma,'*')
WHERE i = SCOPE_IDENTITY()

INSERT INTO @tab
SELECT J
FROM @Tab
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J = REPLACE(j,'|***','*`._')
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J = REPLACE(j,'*,]','].')
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT j
FROM @tab
WHERE i = SCOPE_IDENTITY()

UPDATE @Tab
SET J = REPLACE(J, '`._','**|*')
WHERE i = SCOPE_IDENTITY()

UPDATE @Tab
SET J = REPLACE(J, '`._','**|*')
WHERE i = SCOPE_IDENTITY()

UPDATE @Tab
SET J = REPLACE(J, '`*].','\')
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT J FROM @tab
WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J = REPLACE(j,'**|','_/**')
WHERE i =SCOPE_IDENTITY()
UPDATE @tab
SET J = REPLACE (J,'\','-''\')
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT REPLICATE('*',9)+','+@Comma
UPDATE @tab
SET J = J + REPLACE(J,'*,','**,')
WHERE i = SCOPE_IDENTITY()

INSERT INTO @tab
SELECT REPLICATE('*',7)
UPDATE @tab
SET J = j+'_/'''
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET j = J + REPLICATE('*',10)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET j = J +'\'+ REPLICATE('*',21)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET j = J +',' +REPLICATE('.',5)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET j = J + REPLICATE(',',2)
WHERE i = SCOPE_IDENTITY()

------
INSERT INTO @tab
SELECT REPLICATE('*',2)
UPDATE @tab
SET J=j+CHAR(124)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J=j+Replicate('-',2)+@comma
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J=j+@comma
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J=j+Replicate('*',14)+@comma
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+CAST(0x2D3B5F as varchar)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+REPLICATE('*',8)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+CHAR(124)+Char(92)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+REPLICATE('*',5)+Char(47)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+REPLICATE('*',6)+'.,'+@Comma
WHERE i = SCOPE_IDENTITY()


INSERT INTO @tab
SELECT REPLICATE('*',26)
UPDATE @tab
SET J= STUFF(J,4,1,CHAR(92))
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J=j+CHAR(126)+Replicate('-',2)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J=j+'.'
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J=j+Replicate('_',2)+','+@comma
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+'_*'+@Comma
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+REPLICATE('-',4)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+REPLICATE('*',5)
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= J+',-'+@Comma
WHERE i = SCOPE_IDENTITY()

INSERT INTO @tab
SELECT REPLICATE('*',54)
UPDATE @tab
SET J= STUFF(J,4,2,'`'+CHAR(92))
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= STUFF(J,44,7,CAST(0x5C602D275C5F5F as Varchar))
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J=j+','+CHAR(124)
WHERE i = SCOPE_IDENTITY()

INSERT INTO @tab
SELECT REPLICATE('***',12)
UPDATE @tab
SET J= CAST(0x2C2D2D3B AS Varchar)+CHAR(47)+space(1)+J
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET j=J+CHAR(92)+SPACE(6)+CHAR(47)
WHERE i = SCOPE_IDENTITY()


INSERT INTO @Tab
SELECT SPACE(5)+Char(124)
UPDATE @tab
SET J = CHAR(92)+J
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J = REPLICATE(REPLICATE('*',10),4)+J
WHERE i =SCOPE_IDENTITY()
UPDATE @tab
SET j= CAST(0x5C5F5F as varchar)+j
WHERE i = SCOPE_IDENTITY()

INSERT INTO @tab
SELECT REPLICATE('*',46)
UPDATE @tab
SET J= STUFF(J,3,2,'./')
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= STUFF(J,7,3,'_-,')
WHERE i = SCOPE_IDENTITY()
UPDATE @tab
SET J= STUFF(J,42,2,'*_|')
WHERE i = SCOPE_IDENTITY()


INSERT INTO @Tab
SELECT REPLICATE('*',42)
UPDATE @Tab
SET j = STUFF(j,3,6,CAST(0x5C5F5F2F2A2F as varchar))+'"'
WHERE i = SCOPE_IDENTITY()


INSERT INTO @Tab
SELECT REPLICATE('***',10)
UPDATE @Tab
SET J=STUFF(J,8,1,CHAR(124))+RIGHT(CAST(0x5C5F5F2F2A2F AS Varchar(4)),2 )
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT REPLACE(J,'**_',',') FROM @Tab
WHERE i = SCOPE_IDENTITY()


INSERT INTO @Tab
SELECT REPLACE(REPLACE(J,'|*','\'),',','') FROM @Tab
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT REPLICATE ('*',23)
UPDATE @Tab
SET J = STUFF(J,9,1,Char(124))
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT LEFT('*'+REPLACE(J,CHAR(124),Char(92)),21)
FROM @Tab WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J = J+ CAST(0x2F2E2D27 as varchar)
WHERE i = SCOPE_IDENTITY()-1

INSERT INTO @Tab
SELECT LEFT('*'+REPLACE(J,CHAR(92),Char(124)),20)
FROM @Tab WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J = J+ '_/'
WHERE i = SCOPE_IDENTITY()-1

INSERT INTO @Tab
SELECT LEFT('*'+REPLACE(J,CHAR(92),Char(124)),20)
FROM @Tab WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J = J+ '/'
WHERE i = SCOPE_IDENTITY()-1
UPDATE @Tab
SET J = J+ '|'
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT J FROM @Tab
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT '*'+LEFT(REPLACE(j,CHAR(124),CHAR(92)) ,19 )
FROM @Tab
WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J =J + Char(47)
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT REPLICATE('*',2)+LEFT(j,16)
FROM @Tab
WHERE i = SCOPE_IDENTITY()-2

INSERT INTO @Tab
SELECT (J)
FROM @Tab
WHERE i = SCOPE_IDENTITY()
UPDATE @Tab
SET J= J+'*/'
WHERE i = SCOPE_IDENTITY()-1
UPDATE @Tab
SET J= J+'_|'
WHERE i = SCOPE_IDENTITY()

INSERT INTO @Tab
SELECT REPLICATE('*',14)
UPDATE @Tab
SET J = j+ CAST(0x5C5F2C2F AS Varchar)
WHERE i = SCOPE_IDENTITY()

INSERT INTO @tab
SELECT ''
INSERT INTO @tab
SELECT ''

INSERT INTO @Tab
SELECT SPACE(20)+CAST(0x417274203A2020416E6565736820 as varchar)

select j from @tab

1 comment:

Ritesh said...

Great job Aneesh.