T-sql, sql table internal join table

I have a table (AmenityData) of data, and the column of this table contains mail agents, for example. E14 7

I also have an Excel spreadsheet with a list of postal counties, for example. E14

I need to get all the data from the AmenityData table, where the postal areas are AS the postal sectors, for example. WHERE [PostalDistricts] + '%' LIKE [PostalSector].

The code I'm using at the moment does not appear with an error, but just returns nothing, and I know that a lot of results should come out:

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]

I'm not even sure that you can join tables using LIKE, I have never done this before.

+3
source share
2

LIKE.

+1

.

, .

UPDATE [AmenityData]
SET PostalDistrict = REPLACE(PostalDistrict , ' ', '')

UPDATE [AmenityData]
SET PostalDistrict = LEFT(PostalDistrict ,LEN(PostalDistrict )-1)

,

SELECT * FROM AmenityData As a
INNER JOIN  TypesToGroups As b
ON a.ClassCode =  b.FacilityTypeID
INNER JOIN Groups As c
ON b.GroupID = c.GroupID
INNER JOIN  OPENROWSET ('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=\\Bdzserver\db_creation\postaldistricts.xls;HDR=YES', 'SELECT * FROM [Sheet1$]') As d
ON d.[PostalDistricts] = a.[PostalDistrict]

.

, , , - .

J.

+2

Source: https://habr.com/ru/post/1757112/


All Articles