SQL选择查询链接到具有多个WHERE子句的两个控件

时间:2015-05-12 15:15:43

标签: sql access-vba ms-access-2010

我在下面的SQL select查询中遇到语法错误。使用第一个where子句没有问题。只要我添加第二个,我就会收到语法错误消息。

sql_get = "SELECT tblContacts.ID AS IDResource
                  , tblImmages.Immage
                  , tblContacts.Foto
                  , tblSkillsMatrix01.CurrentLevel
                  , tblSkillsMatrix01.GeneralNotesSymbol
                  , tblSkillsMatrix01.ID
                  , tblSkillsMatrix01.Status
                  , tblSkillsMatrix01.SkillLevelPie
                  , tblSkillsMatrix01.SubProcessID
                  , tblSkillsMatrix01.Contact
                  , tblTeams.Team
                  , tblValueChain01.MacroProcess
                  , tblSkillsMatrix01.LevelOneStatus
                  , tblSkillsMatrix01.AsOfDateL1
                  , tblSkillsMatrix01.LevelTwoStatus
                  , tblSkillsMatrix01.AsOfDateL2
                  , tblSkillsMatrix01.LevelThreeStatus
                  , tblSkillsMatrix01.AsOfDateL3
                  , " & _
                  "tblSkillsMatrix01.LevelFourStatus 
                  , tblSkillsMatrix01.AsOfDateL4
                  , tblSkillsMatrix01.GeneralNotes
                  , tblSkillsMatrix01.LevelOneNotes
                  , tblSkillsMatrix01.LevelTwoNotes
                  , tblSkillsMatrix01.LevelThreeNotes
                  , tblSkillsMatrix01.LevelFourNotes
                  , tblSkillsMatrix01.LevelOneNotesSymbol
                  , tblSkillsMatrix01.LevelTwoNotesSymbol
                  , tblSkillsMatrix01.LevelThreeNotesSymbol
                  , tblSkillsMatrix01.LevelFourNotesSymbol
                  , tblSkillsMatrix01.ExpectedCmplDateL1
                  , tblSkillsMatrix01.ExpectedCmplDateL2
                  , tblSkillsMatrix01.ExpectedCmplDateL3 
                  , tblSkillsMatrix01.ExpectedCmplDateL4 
             FROM (tblTeams 
                  INNER JOIN (tblContacts 
                             INNER JOIN (tblSkillsMatrix01 
                                        INNER JOIN tblImmages ON tblSkillsMatrix01.SkillLevelPie = tblImmages.ID) 
                             ON tblContacts.ID = tblSkillsMatrix01.Contact) 
                  ON tblTeams.ID = tblContacts.Team) 
                  INNER JOIN tblValueChain01 ON tblContacts.Group = tblValueChain01.IDMacroProcesso 
            WHERE [tblValueChain01].[MacroProcess]= '" & Me.MacroProcess & "'" 
               and WHERE [tblSkillsMatrix01].[SubProcessID]= '" & Form_frmValueChain07e.ID & "'"

Me.frmValueChain14.Form.RecordSource = sql_get

2 个答案:

答案 0 :(得分:1)

您在单个WHERE语句中有多个SELECT子句。您不需要两个WHERE子句。

替换此

WHERE [tblValueChain01].[MacroProcess]= '" & Me.MacroProcess & "'" 
and WHERE [tblSkillsMatrix01].[SubProcessID]= '" & Form_frmValueChain07e.ID & "'"

使用此[如果SubProcessID 数字]

WHERE [tblValueChain01].[MacroProcess]= '" & Me.MacroProcess & "' and [tblSkillsMatrix01].[SubProcessID]= '" & Form_frmValueChain07e.ID & "'"

或与此[如果SubProcessID IS 一个数字]

WHERE [tblValueChain01].[MacroProcess]= '" & Me.MacroProcess & "' and [tblSkillsMatrix01].[SubProcessID]= " & Form_frmValueChain07e.ID & ""

并尝试..

答案 1 :(得分:0)

试试这个......

sql_get = "SELECT tblContacts.ID AS IDResource, tblImmages.Immage, tblContacts.Foto, tblSkillsMatrix01.CurrentLevel, tblSkillsMatrix01.GeneralNotesSymbol, tblSkillsMatrix01.ID, tblSkillsMatrix01.Status, tblSkillsMatrix01.SkillLevelPie, tblSkillsMatrix01.SubProcessID, tblSkillsMatrix01.Contact, tblTeams.Team, tblValueChain01.MacroProcess, tblSkillsMatrix01.LevelOneStatus, tblSkillsMatrix01.AsOfDateL1, tblSkillsMatrix01.LevelTwoStatus, tblSkillsMatrix01.AsOfDateL2, tblSkillsMatrix01.LevelThreeStatus, tblSkillsMatrix01.AsOfDateL3, " & _
"tblSkillsMatrix01.LevelFourStatus , tblSkillsMatrix01.AsOfDateL4, tblSkillsMatrix01.GeneralNotes, tblSkillsMatrix01.LevelOneNotes, tblSkillsMatrix01.LevelTwoNotes, tblSkillsMatrix01.LevelThreeNotes, tblSkillsMatrix01.LevelFourNotes, tblSkillsMatrix01.LevelOneNotesSymbol, tblSkillsMatrix01.LevelTwoNotesSymbol, tblSkillsMatrix01.LevelThreeNotesSymbol, tblSkillsMatrix01.LevelFourNotesSymbol, tblSkillsMatrix01.ExpectedCmplDateL1, tblSkillsMatrix01.ExpectedCmplDateL2, tblSkillsMatrix01.ExpectedCmplDateL3 , tblSkillsMatrix01.ExpectedCmplDateL4 FROM (tblTeams INNER JOIN (tblContacts INNER JOIN (tblSkillsMatrix01 INNER JOIN tblImmages ON tblSkillsMatrix01.SkillLevelPie = tblImmages.ID) ON tblContacts.ID = tblSkillsMatrix01.Contact) ON tblTeams.ID = tblContacts.Team) INNER JOIN tblValueChain01 ON tblContacts.Group = tblValueChain01.IDMacroProcesso WHERE [tblValueChain01].[MacroProcess]= '" & Me.MacroProcess & "'" and [tblSkillsMatrix01].[SubProcessID]= '" & Form_frmValueChain07e.ID & "'"
Me.frmValueChain14.Form.RecordSource = sql_get