Urgent need for this query

  • Hi all,

            I have a urgent need in query if I have a number 20.160 it will show 20.16 means 0 should not be there.But if 20.106 the number should be displayed full. trailing zeros should be removed.

            Please help me its urgent.

                                           Million of thanks in advance.

                                                   Manutosh

  • What's the datatpye of the column?

  • The datatype of that column is int but we change it into varchar.

                                      Thanks in advance.

                                             Manutosh

  • with int datatype you don't have decimals

    you could do

    select convert(decimal(11,3),yourIntCol) / 100 as youDecCol 

    (adjust the 11 to your needs !)

    Johan

    Learn to play, play to learn !

    Dont drive faster than your guardian angel can fly ...
    but keeping both feet on the ground wont get you anywhere :w00t:

    - How to post Performance Problems
    - How to post data/code to get the best help[/url]

    - How to prevent a sore throat after hours of presenting ppt

    press F1 for solution, press shift+F1 for urgent solution 😀

    Need a bit of Powershell? How about this

    Who am I ? Sometimes this is me but most of the time this is me

  • Hi ,

              It is still I found 0 in tha last.Suppose I give 20.160 the result should be 20.16 not include 0 at last.

                                                                 Thanks

                                                                      Manutosh

  • alzdba query is working properly

     

  • Hi,

    I have given this query

    select convert(decimal(11,3),20.160)/100

    result-  .2016000

    I need only 20.16

                         Please help me its urgent. I have given this query to my client.

                                         Thanks

                                              Manutosh

                                      

  • Hi,

    I have given this query

    select convert(decimal(11,3),20.160)/100

    result-  .2016000

    I need only 20.16

                         Please help me its urgent. I have given this query to my client.

                                         Thanks

                                              Manutosh

                                      

  • The presentation format of the data should be done on the client that is displaying the data. eg: Excel, Crystal Reports, Reporting Services, etc...

    This is very clunky and NOT what SQL Server should be doing, but I though it would be interesting to try it out.

    DECLARE @result decimal(11,6)
    SELECT @result = 20.1 -- test 1
    SELECT @result, SUBSTRING(CAST(@result as varchar(30)), 1, LEN(@result)-PATINDEX('%[1-9]%', REVERSE(@result)) + 1)
    SELECT @result = 20.16 -- test 2
    SELECT @result, SUBSTRING(CAST(@result as varchar(30)), 1, LEN(@result)-PATINDEX('%[1-9]%', REVERSE(@result)) + 1)
    SELECT @result = 20.106 -- test 3
    SELECT @result, SUBSTRING(CAST(@result as varchar(30)), 1, LEN(@result)-PATINDEX('%[1-9]%', REVERSE(@result)) + 1)
    SELECT @result = 20.1006 -- test 4
    SELECT @result, SUBSTRING(CAST(@result as varchar(30)), 1, LEN(@result)-PATINDEX('%[1-9]%', REVERSE(@result)) + 1)

    Interesting to note that the decimal variable doesn't require explicit casting to varchar for LEN, REVERSE and PATINDEX, but it is required for SUBSTRING

     

    --------------------
    Colt 45 - the original point and click interface

  • Hi

            Thanks Phill

                        It works fine

                                            Manutosh

Viewing 10 posts - 1 through 9 (of 9 total)

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