将 money 数据类型转换为 3 位小数

Convert money datatype to 3 decimal places

我正在尝试以最多 3 位小数的十进制格式显示我的 PT.TotalAmount(money) 字段。我尝试使用

CAST(ROUND(123.4567, 3) AS MONEY)

但是我得到错误:

An object or column name is missing or empty. For SELECT INTO statements, verify each column has a name. For other statements, look for empty alias names. Aliases defined as "" or [] are not allowed. Change the alias to a valid name.

这是我的SP:

Select PT.[ID] 'TransactionID', PT.BatchNumber, PT.SequenceNumber, PT.TransactionDate,   
 PT.TerminalID ,CAST(ROUND(PT.TotalAmount, 2) AS MONEY), PT.TransactionTypeID, TT.TransactionType,     
 PT.PAN 'EmbossLine',PT.PreBalanceAmount, PT.PostBalanceAmount, RefTxnID,   
SettlementDate,PaidCash, CreditAmount, DiscountAmount,    
RefPAN, PT.Remarks, '  ' + CashierCard as 'SupervisorCard',St.StoreID    
into #Temp    
from POS_Transactions PT inner join TransactionType TT on TT.TransactionTypeID = PT.TransactionTypeID     
inner join Staff St on St.CardNumber=PT.CashierCard     
where     
PT.[ID] not in (Select distinct isnull(TransactionID,0) from Testcards)    
and (PT.TransactionDate >= @DateFrom)    
and (PT.TransactionDate < @DateTo)    
and (PT.TransactionTypeID = @TransactionTypeID or @TransactionTypeID = -999)    



select T.*, '&nbsp; '+  C.EmbossLine as 'EmbossLine', '&nbsp;'+ C.EmbossLine as 'EmbossLine1',    

isnull(C.FirstName,'') +' '+ isnull(C.LastName,'') 'EmbossName',C.FirstName,C.LastName,City.CityName,Country.CountryName,Country.CurrencyName,  PM.MerchantID , PM.MerchantName1, C.AccountNumber, C.VehicleNumber    

from #Temp T     

inner join Card C on C.EmbossLine= T.EmbossLine    

inner join Terminal on Terminal.TerminalID = T.TerminalID    

inner join Merchant PM on  PM.MerchantID = Terminal.MerchantID    

inner join City on City.CityID = PM.CityID    

inner join Country on Country.CountryID = PM.CountryID     

where C.Status <>'E3'    

and C.CardID not in (Select distinct isnull(CardID,0) from Testcards)    

and (PM.MerchantID =@MerchantID or @MerchantID='-999')    

and (C.EmbossLine like '%'+@EmbossLine+'%' or @EmbossLine like '-999')    

and (C.FirstName like '%'+@FirstName+'%' or @FirstName like '-999')    

and (C.LastName like '%'+@LastName+'%' or @LastName like '-999')    

and (PM.CountryID = @CountryID or @CountryID ='-999')    

and(PM.CityID = @CityID or @CityID ='-999')    

order by T.TransactionDate, MerchantName1, T.BatchNumber, T.SequenceNumber    

drop table #Temp 

为什么会出现此错误?转换有什么问题?当我在 Select 语句中简单地写 PT.TotalAmount 时,查询成功完成

只需在 sql 查询中添加 CAST(ROUND(PT.TotalAmount, 2) AS MONEY) 的任何别名作为 roundedamont(whatever column name you want)

Select * into 语句要求每列有不同的名称

Select PT.[ID] 'TransactionID', PT.BatchNumber, PT.SequenceNumber, PT.TransactionDate,   
 PT.TerminalID ,CAST(ROUND(PT.TotalAmount, 2) AS MONEY)<----Give Alias HERE