2013-12-10 53 views
0

我有三列SQL Server 2008中嘗試將varchar爲十進制

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; 

結果我想要做的結果有兩個小數和無法弄清楚他是如何施展或轉換陳述來做到這一點的。

+0

相信你已經試過'CAST(SUM(TotalBet)爲十進制)爲SALES'? –

回答

0

你必須將字符串分開並在其中輸入小數。我假設你想要最後2個字符作爲小數?

我把你的數據和做出的東西了證明:

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

SQL Fiddle

相關問題