gpt4 book ai didi

asp.net - '/' 应用程序中的服务器错误无法将字符值转换为金钱

转载 作者:行者123 更新时间:2023-12-03 03:46:31 27 4
gpt4 key购买 nike

我正在运行以下存储过程。结果集绑定(bind)在 gridView 控件上。

@EmbossLine varchar(20),

@TransactionTypeID int,

@DateFrom datetime,

@DateTo datetime

AS

Select

pt.TransactionDate,
m.MerchantName1,
pt.TerminalID,
pt.SequenceNumber,
tt.TransactionType,
case TT.TransactionTypeID when 0 then PT.TotalAmount else 'null' end 'PointsEarned',
case TT.TransactionTypeID when 2 then PT.TotalAmount else 'null' end 'PointsRedemeed'
from POS_Transactions PT
inner join TransactionType TT on TT.TransactionTypeID = PT.TransactionTypeID
inner join CardBalance CB on CB.PAN = PT.PAN
inner join Terminal T on T.TerminalID = PT.TerminalID
inner join Merchant M on M.MerchantID = T.MerchantID
where
(PT.TransactionDate>=@DateFrom and PT.TransactionDate<=@DateTo)
and (PT.TransactionTypeID = @TransactionTypeID or @TransactionTypeID ='-999')
and(PT.PAN=@EmbossLine or PT.PAN='-999')
order by PT.TransactionDate desc

实际上我想做的是,每当我的 TransactionTypeID 不等于 02 时,我想打印 null 。但它会抛出运行时异常

Cannot convert a char value to money. The char value has incorrect syntax.

我知道这是一个转换问题,并且想知道当我的条件评估为 false 时如何打印一些值

最佳答案

更改这两行:

case TT.TransactionTypeID when 0 then PT.TotalAmount else 'null' end 'PointsEarned',
case TT.TransactionTypeID when 2 then PT.TotalAmount else 'null' end 'PointsRedemeed'

对此:

case TT.TransactionTypeID when 0 then PT.TotalAmount else null end 'PointsEarned',
case TT.TransactionTypeID when 2 then PT.TotalAmount else null end 'PointsRedemeed'

您希望在 else 条件中生成 null 值。您当前正在生成单词 'null',这是转换失败的地方 - 您无法转换单词(char 数据类型)'null' 为货币数据类型。

编辑:

您需要将值转换为字符串才能执行此操作。但这意味着您将返回一个字符串,而不是向您的客户端返回货币数据类型。

这种事情确实应该在客户端而不是 SQL Server 中处理。无论如何,请尝试将所有内容转换为字符串:

case TT.TransactionTypeID when 0 then Cast(PT.TotalAmount as varchar(50)) else 'null' end 'PointsEarned',
case TT.TransactionTypeID when 2 then Cast(PT.TotalAmount as varchar(50)) else 'null' end 'PointsRedemeed'

关于asp.net - '/' 应用程序中的服务器错误无法将字符值转换为金钱,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29559469/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com