2012-09-06 37 views
1

此查询的工作子查询和链接服务器

select c.claimid, c.member, c.authno, c.claim_type, c.provider, c.vendor, 
    c.claimdeny, c.date_approved, c.date_received, c.lob 
from xxx.xxx.dbo.clm c 
where c.claimid in (
    select **top 12** d.DENIAL_CLAIM_ID 
    from DN_APPEAL_REQUEST d 
    where d.DENIAL_TYPE='C' order by APPEAL_ID 
) 

此查询不起作用

select c.claimid, c.member, c.authno, c.claim_type, c.provider, c.vendor, 
    c.claimdeny, c.date_approved, c.date_received, c.lob 
from xxx.xxx.dbo.clm c 
where c.claimid in (
    select **top 13** d.DENIAL_CLAIM_ID 
    from DN_APPEAL_REQUEST d 
    where d.DENIAL_TYPE='C' order by APPEAL_ID 
) 

xxx.xxx是链接服务器

第二个查询的运行然后失败,并显示错误消息,指出先前的sql语句格式错误。从第1子查询


结果从第二子查询

913900133  
916303197  
833701140  
028100832  
028100832  
028100832  
835900898  
205407041  
214402039  
112504239  
213601714  
314700730  

结果

913900133  
916303197  
833701140  
028100832  
028100832  
028100832  
835900898  
205407041  
214402039  
112504239  
213601714  
314700730  
214301493 

的dn_appeal_request仅具有18条记录。我试图在每个claimid的链接服务器表上分别运行查询。它的工作没有问题。

+0

'c.claimid'和'd.DENIAL_CLAIM_ID'偶然不同的数据类型?我怀疑一个可能是一个数字字段,另一个是一个char/varchar字段,并且你得到了一个转换错误。 – LittleBobbyTables

+0

相同的数据类型, –

+3

你能告诉我们数据类型吗?你还可以向我们展示从第二个子查询返回的13个值吗? –

回答

0

您可能会感兴趣this answer的用法。

+0

虽然这可能在理论上回答这个问题,[这将是更可取的](http://meta.stackexchange.com/q/8259)在这里包括答案的基本部分,并提供链接供参考。 – Taryn

+0

@bluefeet一个有效的点。谢谢。 –