0

我使用 C# .NET

我需要在我的项目中运行 autodatetime并保存在 SQL Server 中

考试。

在 SQL Server 中

Datetime    | workDate
-------------------------
25-10-2012  | work
26-10-2012  | work
28-10-2012  | work

在我的项目中,我正在搜索 25-28 之间的日期时间

我需要程序输出

25-10-2012  work
26-10-2012  work
27-10-2012  null
28-10-2012  work

但现在我得到:

25-10-2012  work
26-10-2012  work
28-10-2012  work

因为我的数据保存状态仅在状态不起作用时才起作用,所以它不会保存在数据库中。

如何使用插入值 null、向我的项目显示数据并保存在 SQL Server 中?

谢谢你的时间 :)。

4

1 回答 1

0

您可以使用递归 CTE 生成天数列表。

; with  AllDays as
        (
        select  cast('2012-10-25' as date) as dt -- Start date
        union all
        select  dateadd(day, 1, dt)
        from    AllDays
        where   dt < '2012-10-28' -- End date
        )
select  convert(varchar(10), ad.dt, 105)
,       workDate
from    AllDays ad
left join
        Table1 t1
on      t1.Datetime = convert(varchar(10), ad.dt, 105)

SQL FiIddle 上的示例。convertSQL Server 日期更改为105 格式的varchar(10)意大利格式

于 2012-10-28T16:07:26.797 回答