T-SQL,SQL表内部联接电子表格 [英] t-sql, sql table inner join spreadsheet

查看:83
本文介绍了T-SQL,SQL表内部联接电子表格的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据表(AmenityData),此表的一列包含postalsectors,例如E14 7

I have a table (AmenityData) of data and a column of this table contains postalsectors e.g. E14 7

我还有一个Excel电子表格,其中包含邮政区的列表,例如E14

I also have an Excel spreadsheet with a list of postal districts e.g. E14

我需要从AmenityData表中获取所有数据,该表中的邮政区就像邮政区一样,例如在[PostalDistricts] +'%'Like [PostalSector].

I need to get all the data out of the AmenityData table where the postal districts are LIKE the postal sectors e.g. WHERE [PostalDistricts] + '%' LIKE [PostalSector].

我目前正在使用的代码没有出现错误,而是什么也不返回,我知道应该返回很多结果:

The code i'm using at the moment is not coming up with an error but just returning nothing and i know that there should be plenty of results returned:

SELECT * FROM AmenityData As a
INNER JOIN  OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=\\Bdzserver\db_creation\postaldistricts.xls;HDR=YES', 'SELECT * FROM [Sheet1$]') As b
ON b.[PostalDistricts] + '%' LIKE a.[PostalSector]

我什至不确定您是否可以使用LIKE联接表,我以前从未这样做过.

I'm not even sure if you can join tables using a LIKE, i've never done this before.

推荐答案

您需要在LIKE右侧使用通配符.

You need the wildcard on the right side of the LIKE.

这篇关于T-SQL,SQL表内部联接电子表格的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆