[原创]KiWing框架中存储过程Datetime返回类型的问题

最近项目中出现了,通过存储过程查询出来的实体类的Datetime类型的属性没有获得到值,但是执行存储过程有返回值,原存储过程如下:

 

ALTER Procedure [dbo].[Client_TrackMonthSelect]
@PageSize int=0,
@CurrentPage int=1,
@Identifier int=NULL,
@Tracker nvarchar(200)=NULL,
@Create_Date Datetime=NULL,
@StartDate Datetime=null,
@EndDate Datetime=null,
@TrackNum int=null
AS
select identity(int,1,1) as Identifier,convert(char(10),Create_Date,120) as Create_Date,
COUNT(DISTINCT Client_ID) as TrackNum 
into #temp_tails
from Client_TrackRecord as t
where 
(@Tracker is NULL OR Tracker=@Tracker) AND
(convert(char(10),Create_Date,120) between DATEADD(MONTH,DATEDIFF(MONTH,0,@StartDate),0) and DATEADD(DAY,-1,DATEADD(MONTH,1+DATEDIFF(MONTH,0,@StartDate),0)))
group by convert(char(10),Create_Date,120)

select identifier,Create_Date,@Tracker as Tracker,TrackNum,@StartDate as StartDate,@EndDate as EndDate,0 as totalPage,0 as SumCount
from #temp_tails order by Create_Date desc

问题原因是因为已经用Convert将表中的Datetimne转换成了char类型导致直接返回Create_Date是char类型和实体类中声明的datetime的值不一样,于是需要转换下类型为datetime,修改后的存储过程如下:

ALTER Procedure [dbo].[Client_TrackMonthSelect]
@PageSize int=0,
@CurrentPage int=1,
@Identifier int=NULL,
@Tracker nvarchar(200)=NULL,
@Create_Date Datetime=NULL,
@StartDate Datetime=null,
@EndDate Datetime=null,
@TrackNum int=null
AS
select identity(int,1,1) as Identifier,convert(char(10),Create_Date,120) as Create_Date,
COUNT(DISTINCT Client_ID) as TrackNum 
into #temp_tails
from Client_TrackRecord as t
where 
(@Tracker is NULL OR Tracker=@Tracker) AND
(convert(char(10),Create_Date,120) between DATEADD(MONTH,DATEDIFF(MONTH,0,@StartDate),0) and DATEADD(DAY,-1,DATEADD(MONTH,1+DATEDIFF(MONTH,0,@StartDate),0)))
group by convert(char(10),Create_Date,120)

select identifier,CAST(Create_Date as DateTime) as Create_Date,@Tracker as Tracker,TrackNum,@StartDate as StartDate,@EndDate as EndDate,0 as totalPage,0 as SumCount
from #temp_tails order by Create_Date desc
赞(0) 打赏
分享到: 更多 (0)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏