r/SQLServer • • Jul 06 '18

SQL Query for DBAs working today...

SELECT
UPPER(SUBSTRING(a.b,a.c,1)) + 
LOWER(SUBSTRING(a.b,a.c+1,a.d-1) + 
SUBSTRING(a.b,a.e,a.f)) as Message
FROM (
select 2 as id, 9 as c, 2 as d, 12 as e, 1 as f, 'All the goodness in the world' as b UNION ALL
select 1 as id, 20 as c, 4 as d, 1 as e, 1 as f, 'Kindness is better than openness' as b UNION ALL
select 4 as id, 25 as c, 3 as d, 3 as e, 3 as f, 'Today we will eat frenchfries and cheese' as b UNION ALL
select 3 as id, 37 as c, 2 as d, 18 as e, 2 as f, 'Poetry is a human''s endeavour to merit' as b 
) a
order by id

Have a great weekend!

34 Upvotes

13 comments sorted by

10

u/hello_josh Jul 06 '18 edited Jul 06 '18

Back at ya

(Check the spatial results tab)

2

u/[deleted] Jul 06 '18

Well bloody played, my friend. *tips hat.

3

u/MaunaLoona Jul 06 '18

Dear lord...

3

u/IglooDweller Jul 06 '18

Please tell me there's an app for that

3

u/hello_josh Jul 06 '18

Here's the guide I used. Have fun!

1

u/hello_josh Jul 06 '18

I made it long ago. Let me find the tutorial.

3

u/alinroc 4 Jul 06 '18

Slow day at the office, eh?

1

u/[deleted] Jul 06 '18

2

u/chickeeper Jul 06 '18

Bravo solid work

2

u/TNMattH Jul 09 '18

Today's follow-up:

SELECT
UPPER(SUBSTRING(a.b,a.c,1)) + 
LOWER(SUBSTRING(a.b,a.c+1,a.d-1) + 
SUBSTRING(a.b,a.e,a.f) +
SUBSTRING(a.b,a.g,a.h)) as Message
FROM (
select 2 as id, 14 as c, 4 as d, 5 as e, 1 as f, 9 as g, 1 as h, 'Each day has it''s own problems.' as b UNION ALL
select 1 as id, 18 as c, 2 as d, 20 as e, 2 as f, 35 as g, 2 as h, 'Don''t drown your sorrows in whiskey,' as b UNION ALL
select 3 as id, 11 as c, 2 as d, 27 as e, 1 as f, 34 as g, 3 as h, 'Because tomorrow will be another day.' as b
) a
order by id

Now, get back to work. /s

2

u/samalex01 Jul 11 '18

This is awesome!