I have a Stored Procedure having input parameter as @startDate as datetime and I am using this parameter to compare this fields to table column. I want to convert that @startDate field if the timestamp is not passed by the user in SP?

Example: Let's say if user passes @startDate = '01/14/2018 6:30:00 PM' then no it is should be taken as it is in the SP but if @startDate is passed as '01/14/2018' only then it should be converted to '01/14/2018 11:59:59 PM'.

有帮助吗?

解决方案

There's a few ways. Here's one.

declare @startDate datetime = '20180114'

if @startDate = cast(@startDate as date)
begin
    set @startDate = dateadd(second,-1,dateadd(day,1,@startdate))
end

select @startDate
许可以下: CC-BY-SA归因
不隶属于 dba.stackexchange
scroll top