【发布时间】:2015-11-21 09:07:59
【问题描述】:
我正在尝试以小数点后 3 位的十进制格式显示我的 PT.TotalAmount(money) 字段。我尝试使用
CAST(ROUND(123.4567, 3) AS MONEY)
但我得到错误:
对象或列名丢失或为空。对于选择进入 语句,验证每一列都有一个名称。对于其他陈述,请查看 对于空别名。不允许使用定义为 "" 或 [] 的别名。 将别名更改为有效名称。
这是我的 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.*, ' '+ C.EmbossLine as 'EmbossLine', ' '+ 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-server decimal type-conversion currency