将T-SQL转换为Microsoft Access SQL查询

时间:2014-04-15 14:12:42

标签: sql tsql ms-access

我无法将T-SQL代码从SQL Server转换为Microsoft Access sql查询。我已将INNER添加到JOIN中并添加到" dbo _"到表名。你知道我还能做错什么吗?你能不能在访问sql中使用ON?其中一个错误表明加入时出现语法错误?任何帮助,将不胜感激!这是我的代码:

select  distinct
        dbo_Patients.HospitalNumber, 
        dbo_Patients.SocialSecurity, 
        dbo_TextSignals.patientid, 
        dbo_parameters.abbreviation, 
        dbo_parameterstext.text

from dbo_   textsignals 
INNER JOIN dbo_parameterstext
    ON dbo_textsignals.textid=dbo_parameterstext.textid and dbo_textsignals.parameterid = dbo_parameterstext.parameterid
INNER JOIN dbo_parameters
    on dbo_textsignals.parameterid = dbo_parameters.parameterid
INNER JOIN dbo_patients
    on dbo_patients.patientid = dbo_textsignals.patientid

where dbo_textsignals.parameterid in ( 7378, 4640)
and dbo_textsignals.patientid in
                (select distinct patientid 
                 from   signals 
                 where  parameterid = 45 
                        and time  > =  '2013-01-01 00:00:00.000' 
                        and time < '2013-07-01 00:00:00.000') 

order by patientid

1 个答案:

答案 0 :(得分:0)

是的,您可以在MS Access中使用JOINON,但是,您需要将它们括在()括号中。类似的东西:

FROM (((textsignals 
INNER JOIN parameterstext
        ON textsignals.textid = parameterstext.textid
       AND textsignals.parameterid = parameterstext.parameterid)
INNER JOIN parameters
        ON textsignals.parameterid = parameters.parameterid)
INNER JOIN patients
        ON patients.patientid = textsignals.patientid)

或者,您可以使用隐式连接样式(我建议使用上面的显式连接)。这可以通过在FROM中列出所有表格并将所有条件添加到WHERE来实现,如下所示:

FROM textsignals, parameterstext, parameters, patients
WHERE textsignals.textid = parameterstext.textid
  AND textsignals.parameterid = parameterstext.parameterid
  AND textsignals.parameterid = parameters.parameterid
  AND patients.patientid = textsignals.patientid
  AND ..... the other conditions you have ....