Formatting in SQL

  • I'm new to Sql Server but used to work in Access, Sybase, Oracle.

    I'm looking for something like format(value, 'YYYYMMDD') to format a date in a custom format and format(value,'000.00') to have a custom number-format. Is this possible in sql server?

  • Look up CONVERT in BOL ( SQL Server Books Online).

     

  • Many people have asked through this forum about a FORMAT() function. Unfortunately, you'll have to write your own. However, to get you started with the CONVERT() function, here are a few examples that address your specific examples.

    DECLARE @date datetime, @inum int, @fnum float

    SET @date = GetDate()

    SET @inum = 123456

    SET @fnum = 12345.6

    SELECT Convert(varchar(8), @date, 112) AS DateFormat,

           Convert(varchar(20), Convert(money, @inum), 0) AS NumFormat1,

           Convert(varchar(20), Convert(money, @fnum), 0) AS NumFormat2

Viewing 4 posts - 1 through 3 (of 3 total)

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