Home Return length of string for comparison
Reply: 1

Return length of string for comparison

Ollie Beumkes
1#
Ollie Beumkes Published in 2018-02-13 15:51:15Z

Is it possible to compare two strings on the length of the second string for example.

SELECT ProductDescription, Products  
FROM ProductDescription
INNER JOIN Products 
ON ProductDescription LIKE LEFT(Products, LENGTH(Products)) + '%'

Where Products is the string we are comparing with and the length of the comparison I would like to be the same length as the string if that makes sense?

Say we have Hydrogen and Hydrogen Oxide Like matches both so I need to specify what I am comparing...

further more the Description fields may for instance state:

Hydrogen Oxide is water. Oxygen is air. Hydrogen II and Oxygen II can be combined to create water. Hydrogen is a gas. Oxygen II is undefined.

I have a list of states for example: Oxygen. Hydrogen. Oxygen II. Hydrogen II. Hydrogen Oxide.

I would like to append the Correct chemicals to the Descriptions they concern. for example:

Hydrogen Oxide is water. | Hydrogen Oxide. Oxygen is air. | Oxygen Hydrogen II and Oxygen II can be combined to create water. | Hydrogen II, Oxygen II Hydrogen is a gas. | Hydrogen Oxygen II is undefined. | Oxygen II.

The results I can get from the query vary but I am trying to avoid:

Hydrogen Oxide is water. | Hydrogen Oxide. Oxygen is air. | Oxygen. Hydrogen II and Oxygen II can be combined to create water. | Oxygen II. Hydrogen II and Oxygen II can be combined to create water. | Hydrogen. II Hydrogen is a gas. | Hydrogen Oxygen II is undefined. | Oxygen.

Gordon Linoff
2#
Gordon Linoff Reply to 2018-02-14 02:42:34Z

Hmmm. I am thinking you want:

SELECT ProductDescription, Products  
FROM ProductDescription INNER JOIN
     Products 
    ON ProductDescription LIKE Products + '%' OR
       Products LIKE ProductDescription + '%';

This is one way of accomplishing this. Note that the use of LIKE with wildcards will pretty much kill the performance of the query.

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.341039 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO