sql server - Function for word by word string comparison in T-SQL -


i need write sql server function take in 2 fields , perform logical operation in manner
- take first field value, split words
- make sure of these words exist in second field.

for example: first field of le chien , second le chien joue avec la balle function return true in case, since words first 1 in second.

i use substring:

substring(field1, 0, 5)=substring(field2, 0,5)

but in cases not work; if have field1 la maison (1) , field2 la maison (2) substring(field1, 0, 5)=substring(field2, 0,5) return true though strings not match.

increasing number of characters in cases work, not in others. boils down writing function split first string separate words , ensure of them exist in second string.

can me build function or point me in right direction? i'd appreciate help

you can use charindex if want see if value1 exists in value2. https://msdn.microsoft.com/en-us/library/ms186323.aspx

if charindex(value1, value2) > 0  --found 

if words in value 1 can in order in value 2, can use split function jamesz linked in question. once add function database can use

if exists(select  *               dbo.delimitedsplit8k(@value1, ' ')           charindex(item, @value2 ) = 0) -- not found 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -