0

我需要使用 join 2 table 显示所有数据。

考试

表接触

numCode | fullName
00001   | Midna 
00002   | Klog
00003   | Porla
00004   | Seka
00005   | Mila

表日期文件

numCode | dateCurr
00001   | 2012-10-29 00:00:00.000
00002   | 2012-10-29 00:00:00.000
00005   | 2012-10-29 00:00:00.000

代码 Sql 服务器

SELECT df.numCode as 'numCode', tf.dateCurr as 'dateCurr'
FROM dateFile df Full Outer join Contact ct On ct.numCode = df.numCode
WHERE df.dateCurr = '2012-10-29'

输出

numCode | dateCurr
00001   | 2012-10-29 00:00:00.000
00002   | 2012-10-29 00:00:00.000
00005   | 2012-10-29 00:00:00.000

但我需要输出得到:

numCode | dateCurr
00001   | 2012-10-29 00:00:00.000
00002   | 2012-10-29 00:00:00.000
00003   | 2012-10-29 00:00:00.000  (Insert Date from choose datetime)
00004   | 2012-10-29 00:00:00.000  (Insert Date from choose datetime)
00005   | 2012-10-29 00:00:00.000
4

2 回答 2

1

尝试:

SELECT df.numCode as 'numCode', 
       coalesce(tf.dateCurr, '2012-10-29') as 'dateCurr'
FROM dateFile df Full Outer join Contact ct 
On ct.numCode = df.numCode and df.dateCurr = '2012-10-29'
于 2012-10-29T09:10:59.057 回答
0

尝试这个:

select c.numCode,ISNULL(d.dateCurr,'2012-10-29 00:00:00.000') from Contact c left join dateFile d
on c.numCode = d.numCode 
于 2012-10-29T09:44:45.600 回答