我有以下查詢哪些工程很好。但是,我需要獲取郵件地址的實際狀態描述(來自Code_System_State查找表),而不是它的查找代碼c.ContactMailingStateUlink。將連接添加到現有查詢中的lookkup表中?
SELECT
c.ClientID
, cp.ClientULink
, cp.ProgramULink
, c.FirstName
, c.LastName
, c.ContactMailingAddress1
, c.ContactMailingAddress2
, c.ContactMailingCity
, c.ContactMailingStateULink
, c.ContactMailingZip
, c.ContactEmail
, c.ContactHomePhone
, c.ContactCellularPhone
, StartDate
, EndDate
, cp.ProgramStatusULink
from Client_Program cp
INNER JOIN client c ON c.ulink = cp.clientulink
where convert(char(10),cp.StartDate,120) = '2016-02-01'
and convert(char(10),cp.EndDate,120) = convert(CHAR(10),DateAdd(yyyy, 1, cp.StartDate)-1,120)
我想修改我的查詢,如下所示,但得到一個錯誤:「無法綁定‘
’的多部分標識符」 cp.clientulink
SELECT
c.ClientID
, cp.ClientULink
, cp.ProgramULink
, c.FirstName
, c.LastName
, c.ContactMailingAddress1
, c.ContactMailingAddress2
, c.ContactMailingCity
, c.ContactMailingStateULink
, css.Description
, c.ContactMailingZip
, c.ContactEmail
, c.ContactHomePhone
, c.ContactCellularPhone
, StartDate
, EndDate
, cp.ProgramStatusULink
from Client_Program cp, Code_System_State css
INNER JOIN client c ON c.ulink = cp.clientulink
INNER JOIN client ON c.ContactMailingStateUlink = css.code
where convert(char(10),cp.StartDate,120) = '2016-02-01'
and convert(char(10),cp.EndDate,120) = convert(CHAR(10),DateAdd(yyyy, 1, cp.StartDate)-1,120)
如何正確連接這些表?謝謝。
顯示錶定義爲你想加入的2張桌子。我們還沒有足夠的信息。 – ganders
連接不是什麼給錯誤。在表Client_Program中的列clientulink不存在 – SAS
AFAIK,你只能引用FROM語句後的一個表,但你使用兩個:'從Client_Program cp,Code_System_State css' – ksauter