user1240661 user1240661 - 2 months ago 5
SQL Question

TSQL Select where one column equals another column

I'm trying to create a search based on where items go together in the same table.

So if I input a value like

a123
for column
BoxNo
then all values in the column
Goeswith
which are also
a123
are selected. This below code is my attempt, but does not work.

SELECT *
FROM Equipment
WHERE (BoxNo LIKE '%') = GoesWith


thanks

Answer

Maybe you mean,

SELECT  *
FROM    tableName
WHERE   'a123' IN (BoxNo, GoesWith)

or maybe this,

SELECT  *
FROM    tableName
WHERE   BoxNo LIKE '%a123%' AND
        BoxNo = GoesWith
Comments