我有以下查询哪些工程很好。但是,我需要获取邮件地址的实际状态描述(来自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