首先看看我的图片
我需要当join没有找到任何东西来从我的第二个表中获取值
我该怎么做? 这是我的代码:
select * from GridHour
select * from Grid
SELECT a.HistoryID1,a.CustomerID1,CONVERT(VARCHAR(5), b.Hour,108),a.Text1,a.Text2,a.HistoryID2,a.CustomerID2 from Grid a full join GridHour b on a.AppointmentHour=b.hour
答案 0 :(得分:0)
您需要放置2个连接并使用isNull函数,如下所示:
*如果第一个值为null,则采用其他值,如示例
中所示select * from GridHour
select * from Grid
SELECT
a.HistoryID1,
a.CustomerID1,
CONVERT(VARCHAR(5),isnull(b.Hour,c.Hour),108), -- Here put the isnull function
a.Text1,
a.Text2,
a.HistoryID2,
a.CustomerID2
from Grid a
full join GridHour b
on a.AppointmentHour=b.hour
left join Grid c
on a.HistoryID=b.GridID -- Not sure if this is the link