我有一个存储过程,我想根据其中是否为空来决定是选择一列还是其他列。所以我有两列
CreationDate
和ModifiedDate
我的选择是这样的:
SELECT
[P].[LegacyKey] AS [Job No]
,[P].[Name] AS [Proj Name]
FROM Project AS [P]
仅当CreationDate
等于ModifiedDate
,并且NULL
不为空时,我才选择ModifiedDate
。我该如何实现?问候
答案 0 :(得分:2)
您似乎想要coalesce()
:
SELECT [P].[LegacyKey] AS [Job No], [P].[Name] AS [Proj Name],
COALESCE([P].ModifiedDate, [P].CreationDate)
FROM Project AS [P];
答案 1 :(得分:1)
Isnull()也将起作用:
SELECT
[P].[LegacyKey] AS [Job No],
[P].[Name] AS [Proj Name],
ISNULL([P].ModifiedDate, [P].CreationDate)
FROM Project AS [P]