A Geek’s valentines card

What with my wedding only 4 more sleeps away, I’ve not posted yet this week… but I couldn’t resist posting this SQL code… Open up Query Analyser, copy and paste this code into it, press CTRL+T (to make the output show in Text mode (as opposed to Grid/File), and run the query…

Taken from Suresh’s blog posting “Love vs SQL” – he’s a Microsoft MVP in India.

/*
Author: Steve Kass, Drew University
Hosted by: http://vyaskn.tripod.com
Script works on SQL Server 7.0 and 2000
*/
USE tempdb
GO
SET NOCOUNT ON
CREATE TABLE [seqA1740E61-1E21-11D6-B831-E02C0D466A26] (nbr int IDENTITY)
DECLARE @i int
SET @i = 0
WHILE @i < 25
BEGIN
 INSERT INTO [seqA1740E61-1E21-11D6-B831-E02C0D466A26] DEFAULT VALUES
 SET @i = @i + 1
END
DECLARE @heart binary(264)
SET @heart =
  0x010b0e12220b0108100e25
+ 0x080105120a280501031406
+ 0x2a03010215042b02010116
+ 0x022c010100160201000100
+ 0x1602010001000100010001
+ 0x0001000100010101002c01
+ 0x010201002b020104010029
+ 0x0401060100270601080100
+ 0x2508010a0100230a010c01
+ 0x00210c010e01001f0e0110
+ 0x01001d10011201001b1201
+ 0x1401001914011601001716

SELECT
  STUFF(STUFF(STUFF(
      R,A/256,A%256,SPACE(A%256)),
        B/256,B%256,SPACE(B%256)),
        C/256,C%256,SPACE(C%256))
AS N’I love you/Eu te amo/Ti amo/Je t”aime/Ya vas lyublyu/Ich liebe Dich!!!’
FROM (
  SELECT Nbr AS L, SUBSTRING(S,Nbr,2*L) AS R FROM (
    SELECT
      LEN(S+’*’) AS L,
      REPLICATE(S+’*’,4) AS S
    FROM (
      SELECT ‘Happy-Valentine”s-Day’ AS S
    ) X
  ) V CROSS JOIN [seqA1740E61-1E21-11D6-B831-E02C0D466A26]
  WHERE Nbr BETWEEN 1 AND L
) W JOIN (
  SELECT
    Nbr,
    CONVERT(int,SUBSTRING(@heart,6*Nbr-5,2)) AS A,
    CONVERT(int,SUBSTRING(@heart,6*Nbr-3,2)) AS B,
    CONVERT(int,SUBSTRING(@heart,6*Nbr-1,2)) AS C
  FROM [seqA1740E61-1E21-11D6-B831-E02C0D466A26]
  WHERE Nbr BETWEEN 1 AND 24
) X
ON L = Nbr
GO
DROP TABLE [seqA1740E61-1E21-11D6-B831-E02C0D466A26]

Leave a Reply

Your email address will not be published. Required fields are marked *