SQL Server 2008尝试将varchar转换为小数

时间:2013-12-10 19:08:15

标签: sql sql-server-2008 date sum decimal

我有三栏的结果

GameDate    SALES   PRIZES
2013-10-22  2720931 2464831
2013-10-23  3263324 3212128
2013-10-24  2662691 2484328
2013-10-25  4530379 4487401
2013-10-26  1902184 1835012
2013-10-27  2145961 1948877
2013-10-28  1059279 935004
2013-10-29  2493122 2244758
2013-10-30  3309022 2987442

我用它来搞定它

select 
    cast(CurrentDate - 7.0/24 as date) as GameDate,
    SUM(TotalBet) as SALES, SUM(TotalWin) as PRIZES
from 
    play WITH (nolock) 
where 
    CurrentDate > '10/1/2013 00:00:00' and CurrentDate < '10/31/2013 00:00:00'
group by 
    cast(CurrentDate - 7.0/24 as date)
order by 
     1;

我想让结果有两位小数,并且无法弄清楚他是否使用了转换语句来执行此操作。

1 个答案:

答案 0 :(得分:0)

你必须将字符串拆分并在那里推一个小数。我假设你想要最后2个字符作为小数?

我拿走了你的数据并做了一些演示:

sum (cast (left (TotalBet,len(TotalBet)-2) + '.' + right(totalbet,2) as decimal(10,2)))

SQL Fiddle