how to define data type and size from a format function call ?

  • I am wondering:

    how to define data type and size from a format function call ?

    If I define a view like this one, or similar ..  then the column resulting from the format statement is a nvarchar(4000) ..

    create view
    [Clinical].[AAA_Scratch_View]
    as
    select
    format ( getdate() , 'yyyy-MM-dd HH:mm:ss') as [getdateoutput]

    If I am wanting a varchar(19) then this seems to work .. Is this the best way / only way ?

    alter view
    [Clinical].[AAA_Scratch_View]
    as
    select
    CONVERT(VARCHAR(19), format ( getdate() , 'yyyy-MM-dd HH:mm:ss') ) as [getdateoutput]

  • You may want to use convert
    select convert(varchar(19), getdate(), 120) as [getdateoutput];

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply