Welcome to Sign in | Help
in Search

CAST / CONVERT

Last post 02-16-2007, 1:18 PM by Alex. 8 replies.
Sort Posts: Previous Next
  •  02-16-2007, 12:27 PM 1836

    CAST / CONVERT

    salut......unde gresesc de nu-mi afiseaza cu 2 zecimale

     declare @timeInWsSeconds as int
    set @timeInWsSeconds = 19773
    select cast(SUM(@timeInWsSeconds)/3600 as decimal(5,2)) as ORE

     acum imi afiseaza 5 ...iar eu as vrea 5.49

    multumesc

  •  02-16-2007, 12:47 PM 1837 in reply to 1836

    Re: CAST / CONVERT

    Asa si trebuie sa afiseze pentru ca se face impartire intre intregi si scoate intreg, pe urma se face conversia la decimal

    si converteste intregul 5 la 5.00.

    O solutie ar fi ca @timeInWsSeconds sa fie declarat decimal si merge


    Gheorghe Ciubuc,SQL Server Influencer, MCP(SQL 2000), MCTS (SQL Server 2005) , OCA(Oracle 9i), Sybase(Brainbench)
  •  02-16-2007, 1:01 PM 1839 in reply to 1837

    Re: CAST / CONVERT

    nu pot modifica @timeWsSeconds in decimal....el trebuie sa ramana int.....asa e definita in respectivul tabel.

    mai sus am folosit variabila ca am tot testat si d-aia.......cum ar arata scriptul te rog daca as modifica in select timeWsSeconds din int in decimal?

    multumesc

  •  02-16-2007, 1:12 PM 1840 in reply to 1839

    Re: CAST / CONVERT

    am aincercat asa

    declare @timeInWsSeconds as int
    set @timeInWsSeconds = 19773
    select SUM(convert(decimal,@timeInWsSeconds)/3600)  as ORE

    dar am prea multe zecimale vreau sa limitez la 2

    sa-mi ramana doar 5.49

  •  02-16-2007, 1:13 PM 1841 in reply to 1839

    Re: CAST / CONVERT

    declare @timeInWsSeconds as decimal

    set @timeInWsSeconds = 19773
    select cast(SUM(@timeInWsSeconds)/3600 as decimal(5,2)) as ORE

     dar vad ca merge si

    declare @timeInWsSeconds as decimal

    select sum(@timeInWsSeconds)/3600 as ore

    rezultatul este 5.492500 insa pentru pastrarea numai a 2 zecimale se utilizeaza prima varianta


    Gheorghe Ciubuc,SQL Server Influencer, MCP(SQL 2000), MCTS (SQL Server 2005) , OCA(Oracle 9i), Sybase(Brainbench)
  •  02-16-2007, 1:15 PM 1842 in reply to 1840

    Re: CAST / CONVERT

    o sa-l fac asa ca alta varianata nu stiu

    declare @timeInWsSeconds as int
    set @timeInWsSeconds = 19773
    select LEFT(SUM(convert(decimal,@timeInWsSeconds)/3600),4)  as ORE

  •  02-16-2007, 1:16 PM 1843 in reply to 1839

    Re: CAST / CONVERT

    Nu e neaparat nevoie ca variabila sa fie declarata int pt ca un decimal poate "inghiti" numere int, adica

    nr intreg 5434 este vazut decimal asa 5434.00


    Gheorghe Ciubuc,SQL Server Influencer, MCP(SQL 2000), MCTS (SQL Server 2005) , OCA(Oracle 9i), Sybase(Brainbench)
  •  02-16-2007, 1:17 PM 1844 in reply to 1842

    Re: CAST / CONVERT

    sau asa

     

    declare @timeInWsSeconds as int
    set @timeInWsSeconds = 19773
    select cast(SUM(convert(decimal,@timeInWsSeconds)/3600) as decimal(5,2)) as ORE

    multumesc mult ;)

  •  02-16-2007, 1:18 PM 1845 in reply to 1843

    Re: CAST / CONVERT

    variabila trebuie sa fie int.....e o coloana dintr-un tabel de type int....pe care nu o pot modifica

    multumesc

View as RSS news feed in XML
Powered by Community Server (Commercial Edition), by Telligent Systems