问题描述
我正在尝试查询一个表中的on字段,就像另一个表中的字段一样,但是很难获得有效的结果.
I'm trying to query on on field in one table where it is LIKE a field in another table but am having trouble getting valid results.
我想在tbl_Emergin_Current_Device_Listing_20121126
中找到Pager_ID
,就像在tbl_AMCOM_PROD
中的Pager_ID
.
I want to find the Pager_ID
in tbl_Emergin_Current_Device_Listing_20121126
where it is like the Pager_ID
in tbl_AMCOM_PROD
.
一些相关信息:
-
Pager_ID
最多为10个字符,并且始终为数字字符(例如10个字符的Pager_ID:3145551212). - 但是,
tbl_AMCOM_PROD
中的Pager_ID
可以是字母数字(3145551212@att.txt.com,这将是同一用户. - 所有数据都存储为文本.
tbl_Emergin_Current_Device_Listing_20121126
中的Pager_ID
intbl_Emergin_Current_Device_Listing_20121126
is at most 10 characters and are always numeric characters (example of 10 character Pager_ID: 3145551212).- However,
Pager_ID
intbl_AMCOM_PROD
can be alpha-numeric (3145551212@att.txt.com, which would be the same user. - All data is stored as text.
当tbl_Emergin_Current_Device_Listing_20121126.Pager_ID
中存在"3145551212"时,我希望能够在tbl_Amcom_Prod.Pager_ID
中找到"3145551212@att.txt.com".但是,在下面的代码中,我只能找到完全匹配的内容(用EQUAL代替LIKE).
I want to be able to find "3145551212@att.txt.com" in tbl_Amcom_Prod.Pager_ID
when "3145551212" is present in tbl_Emergin_Current_Device_Listing_20121126.Pager_ID
. However, with the code below I'm only finding exact matches (EQUAL instead of LIKE).
当前代码:
SELECT DISTINCT tbl_emergin_current_device_listing_20121126.userrecno,
tbl_emergin_current_device_listing_20121126.username,
tbl_emergin_current_device_listing_20121126.department,
tbl_emergin_current_device_listing_20121126.carriername,
tbl_emergin_current_device_listing_20121126.protocol,
tbl_emergin_current_device_listing_20121126.pin,
tbl_emergin_current_device_listing_20121126.pager_id,
Iif([tbl_amcom_group_call_leads_and_id].[amcom listing msg id],
[tbl_amcom_group_call_leads_and_id].[amcom msg group id],
[tbl_amcom_prod].[messaging_id])
AS [Amcom Messaging or Message Group ID]
FROM ((tbl_emergin_current_device_listing_20121126
LEFT JOIN tbl_amcom_prod
ON tbl_emergin_current_device_listing_20121126.pager_id =
tbl_amcom_prod.pager_id)
LEFT JOIN tbl_amcom_group_call_leads_and_id
ON tbl_emergin_current_device_listing_20121126.pager_id =
tbl_amcom_group_call_leads_and_id.[ams group call lead])
LEFT JOIN tbl_deactivated_pager_list
ON tbl_emergin_current_device_listing_20121126.pager_id =
tbl_deactivated_pager_list.[pager number];
样本结果:
UserRecNo UserName Department CarrierName Protocol PIN PAGER_ID Amcom Messaging or Message Group ID
43 Brown, Lewis BJH Verizon 0 3145550785 3145550785 3145550785
52 Wyman, Mel BJH Airtouch (Verizon) (SNPP) 3 3145558597 3145558597 3145558330
我也想查看此记录,但不是当前代码:
I'd also like to see this record but am not with current code:
57 Johnson, Mick BJH AT&T 3 3145551234 3145551234@att.txt.com 3145559876
我应该做些什么改变?
提前谢谢!
推荐答案
类似的东西
SELECT Pager_ID
FROM tbl_Amcom_Prod a
LEFT JOIN [tbl_Emergin_Current_Device_Listing_20121126] b
On a.Pager_ID & "*" Like b.Pager_ID
这仅适用于SQL视图,不适用于设计视图.
This will only work in SQL view, not design view.
您也可以使用Instr&中.
You could also use a mixture of Instr & Mid.
SELECT IIf(InStr([Pager_ID] & "",".")>0,
Mid([Pager_ID],1,InStr([Pager_ID],".")-1),[Pager_ID ]) AS PID
FROM [tbl_Amcom_Prod]
WHERE IIf(InStr([Pager_ID] & "",".")>0,
Mid([Pager_ID],1,InStr([Pager_ID],".")-1),[Pager_ID])
In (SELECT Pager_ID
FROM [tbl_Emergin_Current_Device_Listing_20121126])
这篇关于访问一个字段与另一个字段相似的查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!