top of page

Welcome to The World of Obscure Uses of Code and SQL – First Stop – Solving the Synoptic Gospel Issue with Transact-SQL

Jun 3

2 min read

2

159

1




Today we are looking to solve the problem of the synoptic gospels with SQL.


Is this possible?


Will we get anywhere?


Probably not.

 

But anyway, away we go.


There is much debate surrounding the synoptic gospels. Did Mark rely on Matthew? Did Matthew rely on Mark? Where does Luke fit in? Is there another document – Q? German scholarship seems to think so.

Does it matter?

What about the apochrypha?

 

Anyway -

Here we go:

 

The first thing we are going to do is upload a biblical database to SQL Server.

We are looking to see if the record of rooster crowing is in all three of the synoptic gospels.

So we just declare the variable ‘cock’.


Two recursive CTEs are declared: selecting the books of Mark and Matthew respectively to ensure that we aren’t scanning the whole of the scriptures.


The function SOUNDEX() determines how a string sounds, this is utilised to have a look at when examining the results.


The DIFFERENCE() function determines the similarity of two strings given the inputs of string 1 and string 2.


It is based on the Levenstein distance which is a mathematical concept with many applications such as autocorrect etc.


This function is probably not as helpful in this situation as the scriptural verses are very long and the translator's placement of verse markers are rather arbitrary.

The code is here:


 

DECLARE

 

@term varchar(max)

 

select @term = 'cock'

 

; WITH MARK AS (

SELECT n, t.id, t.c, t.v, cast(t.t as nvarchar(max)) as t

FROM master.dbo.key_english as k inner join dbo.t_bbe as t

on t.b = k.b

and k.b IN (41))

,

MATTHEW AS (

SELECT n, t.id, t.c, t.v, cast(t.t as nvarchar(max)) as t

FROM master.dbo.key_english as k inner join dbo.t_bbe as t

on t.b = k.b

and k.b IN (40))

SELECT *

FROM (

SELECT *, DIFFERENCE(text_1, text_2) as diff, SOUNDEX(text_1) as sdx, soundex(text_2) as sdx2

FROM (

SELECT M1.t as text_1, 

M2.t as text_2, 

CONCAT(M1.n,' ', M1.c, ' ', M1.v) as Book_Chapter_Verse_1,

CONCAT(M2.n,' ', M2.c,' ',M2.v) as Book_Chapter_Verse_2,

ROW_NUMBER () OVER (PARTITION BY CONCAT(M1.n,' ', M1.c, ' ', M1.v) ORDER BY M1.t) as RN

FROM MARK as M1 INNER JOIN MATTHEW as M2

ON CASE WHEN CHARINDEX(@term,m1.t,1) > 1 THEN 1 ELSE 0 END = CASE WHEN CHARINDEX(@term,m2.t,1) > 1 THEN 1 ELSE 0 END

where CHARINDEX(@term,M1.t,1) > 0

) as X

WHERE RN = 1

) as Y




We can see that there are references to the rooster in Mark and Matthew.

 

What about Mark and Luke?




That is an affirmative.


The rooster crowing occurs in all of the synoptic gospels.

 

So who relied on who?

 

I don’t know.

 

Has this been heretical in any way?

No.

 

Is the Lord Jesus Christ still on the throne?

 

Of course!

 

Have a good day and if anybody happens to read this there will be more obscure SQL coming your way.



Snippet Below:


DECLARE

 

@term varchar(max)

 

select @term = 'cock'

 

; WITH MARK AS (

SELECT n, t.id, t.c, t.v, cast(t.t as nvarchar(max)) as t

FROM master.dbo.key_english as k inner join dbo.t_bbe as t

on t.b = k.b

and k.b IN (41))

,

MATTHEW AS (

SELECT n, t.id, t.c, t.v, cast(t.t as nvarchar(max)) as t

FROM master.dbo.key_english as k inner join dbo.t_bbe as t

on t.b = k.b

and k.b IN (40))

SELECT *

FROM (

SELECT *, DIFFERENCE(text_1, text_2) as diff, SOUNDEX(text_1) as sdx, soundex(text_2) as sdx2

FROM (

SELECT M1.t as text_1, 

M2.t as text_2, 

CONCAT(M1.n,' ', M1.c, ' ', M1.v) as Book_Chapter_Verse_1,

CONCAT(M2.n,' ', M2.c,' ',M2.v) as Book_Chapter_Verse_2,

ROW_NUMBER () OVER (PARTITION BY CONCAT(M1.n,' ', M1.c, ' ', M1.v) ORDER BY M1.t) as RN

FROM MARK as M1 INNER JOIN MATTHEW as M2

ON CASE WHEN CHARINDEX(@term,m1.t,1) > 1 THEN 1 ELSE 0 END = CASE WHEN CHARINDEX(@term,m2.t,1) > 1 THEN 1 ELSE 0 END

where CHARINDEX(@term,M1.t,1) > 0

) as X

WHERE RN = 1

) as Y

Jun 3

2 min read

2

159

1

Comments (1)

Guest
Jul 06

Nice example and what a cool way to share T-SQL knowledge and your faith! :{>

Like
bottom of page