|
database
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Easy Convert QuestionWill the following SQL allow me to see the results of the computed column in
decimal format even if the Columns used in the calculation are defind as int: Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count' I have used it but I am not getting any decimal places. It is showing the decimals as 0. If this is not the problem could you please make some suggestions. Thanks Adam Try multiplying the arguments by 1.0, or explicitly converting the arguments
to decimal. By arguments, I mean the individual pieces, not the result of the calculation. A Show quote "A.B." <A*@discussions.microsoft.com> wrote in message news:836A42B5-D2D1-480B-82A5-A167007B0123@microsoft.com... > Will the following SQL allow me to see the results of the computed column > in > decimal format even if the Columns used in the calculation are defind as > int: > > Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) > 'Count' > > I have used it but I am not getting any decimal places. It is showing the > decimals as 0. If this is not the problem could you please make some > suggestions. > > Thanks > Adam How about something like this
select price/cast(code as money) from xyz i.e. the denominator gets converted to 'money' type :) Cheers, JP (Just a programmer:)) -------------- Show quote "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message news:O515emXqFHA.2652@tk2msftngp13.phx.gbl... > Try multiplying the arguments by 1.0, or explicitly converting the > arguments to decimal. > > By arguments, I mean the individual pieces, not the result of the > calculation. > > A > > > > > "A.B." <A*@discussions.microsoft.com> wrote in message > news:836A42B5-D2D1-480B-82A5-A167007B0123@microsoft.com... >> Will the following SQL allow me to see the results of the computed column >> in >> decimal format even if the Columns used in the calculation are defind as >> int: >> >> Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) >> 'Count' >> >> I have used it but I am not getting any decimal places. It is showing the >> decimals as 0. If this is not the problem could you please make some >> suggestions. >> >> Thanks >> Adam > > OR
select price/cast(code as decimal(10,4)) from xyz Cheers, JP (Just a Programmer;)) --------------- Show quote "JP" <some***@somewhere.com> wrote in message news:ucbhzwXqFHA.3104@TK2MSFTNGP12.phx.gbl... > How about something like this > > select price/cast(code as money) from xyz > > i.e. the denominator gets converted to 'money' type :) > > Cheers, > JP (Just a programmer:)) > -------------- > > "Aaron Bertrand [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in > message news:O515emXqFHA.2652@tk2msftngp13.phx.gbl... >> Try multiplying the arguments by 1.0, or explicitly converting the >> arguments to decimal. >> >> By arguments, I mean the individual pieces, not the result of the >> calculation. >> >> A >> >> >> >> >> "A.B." <A*@discussions.microsoft.com> wrote in message >> news:836A42B5-D2D1-480B-82A5-A167007B0123@microsoft.com... >>> Will the following SQL allow me to see the results of the computed >>> column in >>> decimal format even if the Columns used in the calculation are defind as >>> int: >>> >>> Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) >>> 'Count' >>> >>> I have used it but I am not getting any decimal places. It is showing >>> the >>> decimals as 0. If this is not the problem could you please make some >>> suggestions. >>> >>> Thanks >>> Adam >> >> > > You have to change the formula instead.
((#Operator2.[Count] * 1000.00)/#Closed2.[Dyed Yards]) AMB Show quote "A.B." wrote: > Will the following SQL allow me to see the results of the computed column in > decimal format even if the Columns used in the calculation are defind as int: > > Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count' > > I have used it but I am not getting any decimal places. It is showing the > decimals as 0. If this is not the problem could you please make some > suggestions. > > Thanks > Adam Can you try this:
Convert(Dec(10,5), ((#Operator2.[Count]*1000.0)/#Closed2.[Dyed Yards])) 'Count' Perayu Show quote "A.B." wrote: > Will the following SQL allow me to see the results of the computed column in > decimal format even if the Columns used in the calculation are defind as int: > > Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count' > > I have used it but I am not getting any decimal places. It is showing the > decimals as 0. If this is not the problem could you please make some > suggestions. > > Thanks > Adam Thanks guys, it worked
Show quote "A.B." wrote: > Will the following SQL allow me to see the results of the computed column in > decimal format even if the Columns used in the calculation are defind as int: > > Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count' > > I have used it but I am not getting any decimal places. It is showing the > decimals as 0. If this is not the problem could you please make some > suggestions. > > Thanks > Adam hi AB
you can try it as: #Operator2.[Count]*1000.0)/#Closed2.[Dyed Yards] as [count] hope this will help u -- Show quotebest Regards, Chandra http://chanduas.blogspot.com/ http://www.SQLResource.com/ --------------------------------------- "A.B." wrote: > Will the following SQL allow me to see the results of the computed column in > decimal format even if the Columns used in the calculation are defind as int: > > Convert(Dec(10,5), ((#Operator2.[Count]*1000)/#Closed2.[Dyed Yards])) 'Count' > > I have used it but I am not getting any decimal places. It is showing the > decimals as 0. If this is not the problem could you please make some > suggestions. > > Thanks > Adam |
|||||||||||||||||||||||