INNER JOIN加入表达式不受支持?

时间:2012-02-12 13:43:09

标签: sql ms-access inner-join

我遇到以下SQL查询的问题:

select 
    [customer].teskilat_kodu, [customer].hesab_nomresi,
    [customer].soyad, [customer].ad, [customer].ataadi, [customer].unvan,
    [customer].tevellud, [customer].nomre, [customer].cins, [customer].status,
    [customer].qohum_nomresi, [customer].email 
from 
    [customer] 
INNER JOIN 
    [kart_novleri] ON [kart_novleri].id = '[customer].kart_novu'  
ORDER BY 
    [customer].id ASC

它返回错误:

  

错误:不支持连接表达式

1 个答案:

答案 0 :(得分:0)

访问(未经测试):

select 
    [customer].teskilat_kodu, [customer].hesab_nomresi,
    [customer].soyad, [customer].ad, [customer].ataadi, [customer].unvan,
    [customer].tevellud, [customer].nomre, [customer].cins, [customer].status,
    [customer].qohum_nomresi, [customer].email 
from 
    [customer] 
INNER JOIN 
    [kart_novleri] ON [kart_novleri].id = CInt([customer].kart_novu)
ORDER BY 
    [customer].id ASC

在TSQL中,这样的事情应该有效:

select 
    [customer].teskilat_kodu, [customer].hesab_nomresi,
    [customer].soyad, [customer].ad, [customer].ataadi, [customer].unvan,
    [customer].tevellud, [customer].nomre, [customer].cins, [customer].status,
    [customer].qohum_nomresi, [customer].email 
from 
    [customer] 
INNER JOIN 
    [kart_novleri] ON cast([kart_novleri].id as varchar(max)) = [customer].kart_novu 
ORDER BY 
    [customer].id ASC

或者

select 
    [customer].teskilat_kodu, [customer].hesab_nomresi,
    [customer].soyad, [customer].ad, [customer].ataadi, [customer].unvan,
    [customer].tevellud, [customer].nomre, [customer].cins, [customer].status,
    [customer].qohum_nomresi, [customer].email 
from 
    [customer] 
INNER JOIN 
    [kart_novleri] ON [kart_novleri].id = cast([customer].kart_novu as int)
ORDER BY 
    [customer].id ASC

根据您的数据,您可能希望对联接之前的强制转换结果执行“isnumber”以避免致命错误。我建议使用CTE在连接之前“按下”列以确保稳健性 - 或者将原始值存储为int!