Can you join on text?

  • I have two tables that have nothing in common except for a text Desc column.

    I've tried casting them and substring but I get error 207 invalid column.

    Open to all suggestions.:-D

    😎
    Billy

  • yes, it'll be a bit slow, because you'll have to convert the TEXT field to a varchar(8000);

    here's an examplei put together, note how i made a searchterm in a subquery, because you might want to find some specific string in one of the descriptions.

    SELECT T1.DESCRIP,T2.DESCRIP

    FROM T1

    LEFT OUTER JOIN

    (SELECT

    SUBSTRING(CONVERT(VARCHAR(8000),T2.DESCRIP),1,40) AS SEARCHTERM,

    DESCRIP

    FROM T2) AS T2

    --hope the first 40 characters exist in t1?

    ON CONVERT(VARCHAR(8000),T2.DESCRIP) LIKE '%' + T2.SEARCHTERM + '%'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • You could cast them to varchar(max) to do the join, or better yet, convert the columns to varchar(max).

    A way you could speed this up is to create an indexed integer column that contains a checksum of the TEXT column, and then join on the checksum column with a secondary compare on the value in the text column to eliminate duplicates.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply