none
how to update decimal values in sql server? RRS feed

  • Question

  • Hi all

    My Code is..

    UPDATE dbo.Table1 SET Quanty=3.75

    and See DataType ...

    But when run this code 

    I get 0 result in my table .

    How to solve it?

    Please Help me.

    Thanks all


    Name of Allah, Most Gracious, Most Merciful and He created the human

    Friday, June 28, 2019 7:06 AM

All replies

  • Hi sh2018,

    I test your code but it works. I'm wondering if you've set triggers or something else in your code. Can you please offer us the completed one you have? 

    There's nothing wrong with your current code.  

    DROP TABLE IF EXISTS dbo.table1;
    GO
    CREATE TABLE dbo.Table1(Quanty float not null );
    
    set nocount on 
    
    INSERT INTO Table1 VALUES 
    (0)
    select * from table1
    
    update Table1
    SET Quanty=3.75
    
    
    select * from table1
    
    /*
    Quanty
    ----------------------
    3.75
    */

    Regards,

    Sabrina


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    • Proposed as answer by Maia Leslie Friday, July 5, 2019 9:15 AM
    Friday, June 28, 2019 8:38 AM
  • It works to me too. I tried with SQL 2008 r2 and 2016. Same result. 

    create table #forum (quanty float)
    
    insert into #forum values (3.75)
    
    select * from #forum
    
    update #forum set quanty=4.75
    
    select * from #forum

    Probably there is something else you should tell us.  However, can you try, line by line, my code and tell us what is the result?

    • Proposed as answer by Maia Leslie Friday, July 5, 2019 9:15 AM
    Friday, June 28, 2019 8:43 AM
  • Can you send the other queries used in this scenario like CREATE, INSERT and SELECT
    Friday, June 28, 2019 10:44 AM
  • There is a big difference between floating-point numbers and decimal (P, S) numbers. What are you actually trying to do? 

    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking in Sets / Trees and Hierarchies in SQL

    Friday, June 28, 2019 3:36 PM
  • Hi sh 2019,

     

    I am writing to follow up this thread with you. Have you solved your issue? If you have solved your issue ,in order to close this thread, please kindly mark helpful replies as answers. By doing so, it will benefit all community members who are having this similar issue.  Your contribution is highly appreciated.

     

    Regards,

    Sabrina


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Monday, July 15, 2019 7:12 AM