使用Access 2003
两个表,Tmp_cardevent1,tmp_cardevent3
查询
SELECT AllPossibleCardEvents.PersonId, AllPossibleCardEvents.CardEventDate, Actual.Intime FROM ((SELECT p.PersonId, AllDates.CardEventDate FROM (SELECT DISTINCT CardEventDate FROM TMP_Cardevent3) AllDates, Tmp_cardevent1 p) AllPossibleCardEvents LEFT OUTER JOIN TMP_cardevent3 Actual ON AllPossibleCardEvents.PersonId = Actual.PersonId AND AllPossibleCardEvents.CardEventDate = Actual.CardEventDate)
输出
PERSONID CardEventDate Intime
3156 05/08/2008
3335 05/08/2008
3405 05/08/2008 20:58:58
3406 05/08/2008
3410 05/08/2008
3422 05/08/2008
3424 05/08/2008
3441 05/08/2008
3447 05/08/2008
3461 05/08/2008
48 05/08/2008
484 05/08/2008
5 05/08/2008
5008 05/08/2008 20:01:45
所以......,
对于Blank Intime列,我想显示为'-----'
尝试查询
SELECT PERSONID, CARDEVENTDATE, INTIME FROM
(SELECT AllPossibleCardEvents.PersonId, AllPossibleCardEvents.CardEventDate, (iif(Actual.Intime=’’, ‘-----‘,Actual.Intime) as Intime FROM ((SELECT p.PersonId, AllDates.CardEventDate FROM (SELECT DISTINCT CardEventDate FROM TMP_Cardevent3) AllDates, Tmp_cardevent1 p) AllPossibleCardEvents LEFT OUTER JOIN TMP_cardevent3 Actual ON AllPossibleCardEvents.PersonId = Actual.PersonId AND AllPossibleCardEvents.CardEventDate = Actual.CardEventDate) )
但是我无法更新空列,结构是否可用于Intime列
预期产出
PERSONID CardEventDate Intime
3156 05/08/2008 -----
3335 05/08/2008 -----
3405 05/08/2008 20:58:58
3406 05/08/2008 -----
3410 05/08/2008 -----
3422 05/08/2008 -----
3424 05/08/2008 -----
3441 05/08/2008 -----
3447 05/08/2008 -----
3461 05/08/2008 -----
48 05/08/2008 -----
484 05/08/2008 -----
5 05/08/2008 -----
5008 05/08/2008 20:01:45
如何查询此空列?
答案 0 :(得分:1)
您可以使用IsNull内置功能。</ p>
SELECT
PERSONID,
CARDEVENTDATE,
INTIME
FROM
(SELECT
AllPossibleCardEvents.PersonId,
AllPossibleCardEvents.CardEventDate,
(iif(iif(IsNull(Actual.Intime), '', Actual.Intime)='', '-----', Actual.Intime) as Intime
FROM ((SELECT
p.PersonId,
AllDates.CardEventDate FROM
(SELECT DISTINCT
CardEventDate FROM TMP_Cardevent3) AllDates,
Tmp_cardevent1 p) AllPossibleCardEvents
LEFT OUTER JOIN TMP_cardevent3 Actual
ON AllPossibleCardEvents.PersonId = Actual.PersonId AND
AllPossibleCardEvents.CardEventDate = Actual.CardEventDate))