Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 Site Related Forums
 The Yak Corral
 Silly Queries.....

Author  Topic 

JBelthoff
Posting Yak Master

173 Posts

Posted - 2008-08-18 : 12:11:15
OK It's Monday. I love this forum! Read it all the time. I am going on vacation tomorrow and was hoping to get some silly examples of useless queries just for fun.

Here is my contribution

select 'as' as [as] order by newid()




JBelthoff
• Hosts Station is a Professional Asp Hosting Provider
› As far as myself... I do this for fun!

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-18 : 12:16:39
moved here since it's a topic for the corral

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

Transact Charlie
Master Smack Fu Yak Hacker

3451 Posts

Posted - 2008-08-19 : 07:38:57
[code]
CREATE TABLE #Words
(
key_col int NOT NULL IDENTITY PRIMARY KEY,
word varchar(15) NOT NULL
)

SET NOCOUNT ON

INSERT INTO #Words VALUES( 0x6966 )
INSERT INTO #Words VALUES( 0x796f75 )
INSERT INTO #Words VALUES( 0x63616E )
INSERT INTO #Words VALUES( 0x72656164 )
INSERT INTO #Words VALUES( 0x74686973 )
INSERT INTO #Words VALUES( 0x776974686F7574 )
INSERT INTO #Words VALUES( 0x657865637574696E67 )
INSERT INTO #Words VALUES( 0x7468656E )
INSERT INTO #Words VALUES( 0x796F75 )
INSERT INTO #Words VALUES( 0x617265 )
INSERT INTO #Words VALUES( 0x61 )
INSERT INTO #Words VALUES( 0x74727565 )
INSERT INTO #Words VALUES( 0x6765656B )


SELECT
CASE
WHEN key_col IN(2,3,max_key-1,max_key-2) THEN REPLICATE('/',4)
ELSE SPACE(4)
END +
CASE
WHEN key_col IN(max_key/2,max_key/2+1) THEN REPLICATE('/', 8)
ELSE SPACE(8)
END +
SPACE(SQRT(SQUARE(radius)-SQUARE(ABS(radius-key_col+1)))) +
CAST(word AS VARCHAR(15)) +
REPLICATE('~', max_len - LEN(word))
FROM #Words
CROSS JOIN
(SELECT
(1. * COUNT(*) - 1) / 2 AS radius,
MAX(LEN(word)) AS max_len,
MAX(key_col) AS max_key
FROM #Words) AS R
ORDER BY key_col

DROP TABLE #Words
[/code]

-------------
Charlie
Go to Top of Page

jezemine
Master Smack Fu Yak Hacker

2886 Posts

Posted - 2008-08-19 : 09:47:22
quines are neat. this is not mine:


set quoted_identifier off
declare @a varchar(147)
declare @b varchar(37)
declare @sq char
declare @dq char
declare @qm char
set @a='set quoted_identifier off
declare @a varchar(147)
declare @b varchar(37)
declare @sq char
declare @dq char
declare @qm char
set @a='
set @sq="'"
set @dq='"'
set @qm='?'
set @b='
print replace(@a,@qm,@sq)+@a+@sq+@b'
print @a+@sq+@a+@sq
print 'set @sq='+@dq+@sq+@dq
print 'set @dq='+@sq+@dq+@sq
print 'set @qm='+@sq+@qm+@sq
print 'set @b='+@sq+@b+@sq
set @a='print @a+@sq+@a+@sq
print ?set @sq=?+@dq+@sq+@dq
print ?set @dq=?+@sq+@dq+@sq
print ?set @qm=?+@sq+@qm+@sq
print ?set @b=?+@sq+@b+@sq
set @a=?'
print replace(@a,@qm,@sq)+@a+@sq+@b


from: http://www.trollied.org/~blimey/quines.php


elsasoft.org
Go to Top of Page

mfemenel
Professor Frink

1421 Posts

Posted - 2008-08-19 : 15:04:02
while this query does have a purpose, I do consider it silly. I actually just found it in production.

select * from
(select btskey,sectorid,sectorkey
tablenamechangedhere) as reftable
where reftable.btskey=16027 and reftable.sectorid=1

Mike
"oh, that monkey is going to pay"
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-19 : 15:14:45
http://weblogs.sqlteam.com/tarad/archive/2004/03/15/1060.aspx

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2008-08-19 : 17:24:28
Not a silly query but just an tidbit of usefull information. It's a bad idea to name your user created stored procedures to begin with "sp_".
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-08-19 : 17:33:40
quote:
Originally posted by Van

Not a silly query but just an tidbit of usefull information. It's a bad idea to name your user created stored procedures to begin with "sp_".


great info, thanks!
Just don't post it on your blog then post several topics and responses under various usernames promoting your blog

Be One with the Optimizer
TG
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2008-08-19 : 17:35:20
She deleted her blog. It was quite amusing, but I suspect we hurt her feelings.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-08-19 : 17:43:12
well then she's not for blogging... someone will surely hurt your feeling at one time.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.0 out!
Go to Top of Page

Van
Constraint Violating Yak Guru

462 Posts

Posted - 2008-08-19 : 18:00:40
It's also faster, better, easier and more straightforward to have a bit column for every nullable column in your database and have it set to 0 if the column isn't populated and just populate the nullable field to 0 or '' if it's null. That way you don't have to use the "IS NULL" syntax. Much much better way to do it than actually populateing with a NULL.

For other usefull tips check out:
http://it.toolbox.com/people/sqlusa
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-08-19 : 18:06:01
that is silly - but it's not a query.

Planning replaces chance by mistake
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-08-19 : 18:19:50
quote:
Originally posted by tkizer

She deleted her blog. It was quite amusing, but I suspect we hurt her feelings.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog



yep - I suspect you're right about that. Too bad, I never thought there was anything wrong with posting accurate information even if it's well known - just unfortunate she got busted (and slightly flamed) promoting it under a different username

Be One with the Optimizer
TG
Go to Top of Page

DavidChel
Constraint Violating Yak Guru

474 Posts

Posted - 2008-08-20 : 09:03:24
quote:
Originally posted by Van

Not a silly query but just an tidbit of usefull information. It's a bad idea to name your user created stored procedures to begin with "sp_".



::golf claps::
Go to Top of Page
   

- Advertisement -