开发者

Comparing two sql values that are almost the same

开发者 https://www.devze.com 2023-03-22 23:41 出处:网络
Comparing two sql values that are almost the same. I know this is simple but I can\'t think how to do it

Comparing two sql values that are almost the same.

I know this is simple but I can't think how to do it

I want to do a join or a "select where = " on t开发者_开发问答wo values in two tables. Problem is one table has a filname with an extension and the other has the filename without the extension. I want to ignore the extension and just do my compare. How would I do that?

I have something simple like this.

select thing1, thing2
where tableName.filename=tableName2.fileName
from tableName,tableName2


Please don't use a multi-part from clause. Use the join syntax instead.

Assuming tableName has the extension and tableName2 does not:

select
    thing1,
    thing2

from tableName tn

join tableName2 tn2 on tn.fileName like tn2.fileName + '.%'


Assuming the DB is SQL Server and tableName2 has the entry without the file extension,

Try this:

select thing1, thing2 
from tableName,tableName2 
where tableName.filename LIKE tableName2.fileName  + '%'
0

精彩评论

暂无评论...
验证码 换一张
取 消