Advertisement
Guest User

Untitled

a guest
Feb 20th, 2019
174
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. STREET STREETNAME
  2. ----------- -----------------
  3. ORANGE ORANGE BLOSSOM
  4. MAIN 324-A MAIN STREET
  5.  
  6. ORANGE
  7. MAIN
  8.  
  9. declare @mytable table
  10. (
  11. id int,
  12. word1 varchar(100),
  13. word2 varchar(100),
  14. word1word2 varchar(100)
  15. )
  16.  
  17. update @mytable
  18. set
  19. word1word2 = f.word1word2
  20. from
  21. (
  22. select
  23. id,
  24. dbo.match(cola, colb) word1word2
  25. from @tablename
  26. ) f
  27. where
  28. [@mytable].id = f.id
  29.  
  30. select
  31. id,
  32. dbo.match(cola, colb) word1word2
  33. from @tablename
  34.  
  35. create function match
  36. (
  37. @word1 varchar(100),
  38. @word2 varchar(100)
  39. )
  40. returns varchar(100)
  41. as
  42. begin
  43.  
  44. declare
  45. @match varchar(100) = '',
  46. @i int = 1
  47.  
  48. while @i <= len(@word1) and @i <= len(@word2)
  49. begin
  50.  
  51. if substring(@word1, @i, 1) = substring(@word2, @i, 1)
  52. begin
  53. set @match = @match + substring(@word1, @i, 1)
  54. end
  55. else
  56. begin
  57. break
  58. end
  59. set @i = @i + 1
  60.  
  61. end
  62.  
  63. return rtrim(@match)
  64.  
  65. end
  66.  
  67. select dbo.match('my first', 'my second')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement