sql server 2008 - Simple T-SQL function to convert date to displayable format -


i have strange bug cannot resolve (with 1 line function).

this code works:

declare @testdate datetime = '2013-05-01 23:15:11' select isnull(convert(varchar(max), @testdate, 120), 'null') 'test1'  

displays: 2013-05-01 23:15:11

create function [dbo].[dateornulltochar] (@inputdate date) returns varchar(40) begin    return isnull(convert(varchar(40),@inputdate, 120),'null');  end select dbo.dateornulltochar('2013-05-01 23:15:11') 'result' 

returns: 2013-05-01 (no time)

i have tried varchar(max).

the purpose of function this:

set @errormessage = ' @arrivaldate=' + dbo.dateornulltochar(@arrivaldate) +                      ' @departuredate=' + dbo.dateornulltochar(@departuredate);  

if 1 value null, whole value becomes null. want see string 'null' when date has null value.

@inputdate should datetime or datetime2 if want time shown

the clues in code...

  • @testdate datetime
  • @inputdate date

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

c++ - qgraphicsview horizontal scrolling always has a vertical delta -