Diciamo che ho un set di 2 parole:T-SQL Get percentuale di partita carattere di 2 stringhe
Alexander e Alecsander OR Alessandro e Alegzander
Alessandro e Aleaxnder, o qualsiasi altra combinazione. In generale stiamo parlando di errore umano nella digitazione di una parola o di un insieme di parole.
Quello che voglio ottenere è ottenere la percentuale di corrispondenza dei caratteri delle 2 stringhe.
Ecco quello che ho finora:
DECLARE @table1 TABLE
(
nr INT
, ch CHAR
)
DECLARE @table2 TABLE
(
nr INT
, ch CHAR
)
INSERT INTO @table1
SELECT nr,ch FROM [dbo].[SplitStringIntoCharacters] ('WORD w') --> return a table of characters(spaces included)
INSERT INTO @table2
SELECT nr,ch FROM [dbo].[SplitStringIntoCharacters] ('WORD 5')
DECLARE @resultsTable TABLE
(
ch1 CHAR
, ch2 CHAR
)
INSERT INTO @resultsTable
SELECT DISTINCt t1.ch ch1, t2.ch ch2 FROM @table1 t1
FULL JOIN @table2 t2 ON t1.ch = t2.ch --> returns both matches and missmatches
SELECT * FROM @resultsTable
DECLARE @nrOfMathches INT, @nrOfMismatches INT, @nrOfRowsInResultsTable INT
SELECT @nrOfMathches = COUNT(1) FROM @resultsTable WHERE ch1 IS NOT NULL AND ch2 IS NOT NULL
SELECT @nrOfMismatches = COUNT(1) FROM @resultsTable WHERE ch1 IS NULL OR ch2 IS NULL
SELECT @nrOfRowsInResultsTable = COUNT(1) FROM @resultsTable
SELECT @nrOfMathches * 100/@nrOfRowsInResultsTable
Il SELECT * FROM @resultsTable
restituirà il seguente:
ch1 ch2
NULL 5
[blank] [blank]
D D
O O
R R
W W
E qual è il problema? Il codice funziona correttamente? –
Che non è preciso. –