开发者

T-sql on on ip range

开发者 https://www.devze.com 2023-01-05 12:48 出处:网络
I have two table in a sql databse one has \"institutionName, ipAddress\" columns and the other one has \"ipAdddress, totalH开发者_开发技巧its\". I want to join the two table based on ipAddress field,

I have two table in a sql databse one has "institutionName, ipAddress" columns and the other one has "ipAdddress, totalH开发者_开发技巧its". I want to join the two table based on ipAddress field, but the problem is the ipAddress in the first table is in a for of "xxx.xxx.xxx.xxx" but in the second table it is in three forms ie "xxx.xxx.xxx.xxx" or "xxx.xxx.." or "xxx.xxx.xxx.*" how can I do this. I am new to T-sql and I really need your help.


Given table A holds institutionName and table B has totalHits.

Based upon your brief description of the data, it should be possible to strip off repeated dots in the ipAddress field on table B. This will allow you to join using a simple prefix string comparison.

SELECT A.institutionName, B.totalHits
FROM A JOIN B ON A.ipAddress LIKE REPLACE(B.ipAddress, '..', '') + '%'
0

精彩评论

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