MaxPlaces列有时有一个值,有时只是NULL。 我必须将此过程发送到C#,但是当在代码中处理NULL时,代码将中断。
ISNULL无法正常工作,将出现以下错误:
其他信息:“ MaxPlaces”列不属于表 getLvLValue。
<div class = "row">
<div class ="col-lg-12">
//put your all child div here which you wants to keep in one row and properly divide the col-lg-12 for every child div
</div>
</div>
有人可以帮助我解决这个问题。仅需要发送一个参数,如果MaxPlaces为NULL,则将值20发送到C#。
谢谢!
答案 0 :(得分:3)
它应该可以工作,但是您没有给结果列指定别名,请尝试以下操作:
ALTER PROCEDURE [dbo].[getLvLValue]
@LevID nvarchar(100)
AS
BEGIN
SELECT a.BCID
, a.CharacteristicID
, b.CharacteristicName
, a.LevID, ISNULL(b.MaxPlaces, '20') as MaxPlaces --here was the issue
FROM BCCharacteristics AS a INNER JOIN Characteristic AS b ON a.CharaID = b.CharaID
WHERE LevID =1 AND a.BCID = @LevelID AND a.CharaID = b.CharaID;
END
答案 1 :(得分:1)
您应提供列名
ALTER PROCEDURE [dbo].[getLvLValue]
@LevID nvarchar(100)
AS
BEGIN
SELECT a.BCID, a.CharacteristicID, b.CharacteristicName, a.LevID, ISNULL(b.MaxPlaces, '20') as MaxPlaces
FROM BCCharacteristics AS a INNER JOIN Characteristic AS b ON a.CharaID = b.CharaID
WHERE LevID =1 AND a.BCID = @LevelID AND a.CharaID = b.CharaID;
END