none
Convert query for sql 2008 r2 RRS feed

  • Question

  • I am using sql 2008 r2 

    i want to convert both below query for sql 2008 R2

    Select Top(1) format(L_Amt, 'N0')  from tbl_Limit ORDER BY L_ID DESC
    
    SELECT FORMAT(Sum(cast(imp_DT as numeric)),'##,###,##,###')  FROM tbl_Import
    it is working in 2014 ,but not working in 2008 R2


    akhter


    • Edited by Akhterhussain Tuesday, June 30, 2020 5:10 PM add remarks
    Tuesday, June 30, 2020 5:09 PM

Answers

  • For your first query you can use

    LTRIM(STR(myNumericValue)) as Formatted.

    For the second it's a bit trickier and I haven't tried to create it using T-SQL only, it would be easier to format on the client's side.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles


    Tuesday, June 30, 2020 7:42 PM
    Moderator

All replies

  • Are you sure you want to format your data in SQL Server and not on the client?

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    Tuesday, June 30, 2020 5:28 PM
    Moderator
  • on client side 

    akhter

    Tuesday, June 30, 2020 5:43 PM
  • If this is the case, then use appropriate code or set up properties in that client depending on which client do you use and just return raw data directly.

    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles

    Tuesday, June 30, 2020 6:14 PM
    Moderator
  • I just want to same result in 2008 r2 ,by using query which i shared,but these queries are not working

    akhter

    Tuesday, June 30, 2020 6:42 PM
  • FORMAT() is a SQL 2012+ command which converts values to a string. 

    If you just want the actual values, and format the values on the client instead, then just remove FORMAT().

    Select Top(1) L_Amt  from tbl_Limit ORDER BY L_ID DESC
    
    SELECT Sum(cast(imp_DT as numeric))  FROM tbl_Import

    Tuesday, June 30, 2020 7:37 PM
    Moderator
  • For your first query you can use

    LTRIM(STR(myNumericValue)) as Formatted.

    For the second it's a bit trickier and I haven't tried to create it using T-SQL only, it would be easier to format on the client's side.


    For every expert, there is an equal and opposite expert. - Becker's Law


    My blog


    My TechNet articles


    Tuesday, June 30, 2020 7:42 PM
    Moderator