SQL IIF Isnull 和更新集 = 0
SQL IIF Isnull and Update set = 0
我的好参考是How to replace blank (null ) values with 0 for all records?
目标 :我有空白查询输出。 Image0 我希望打印出 0。
问题:当我尝试IIF Isnull
时,我得到一个提示信息框输入参数值,这是我不想看到的。 Image1
PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
SELECT Sum(dbo_SO_SalesHistory.DollarsSold) AS SumOfDollarsSold, IIF(ISNULL([SumOfDollarsSold]), 0, [SumOfDollarsSold])
FROM dbo_SO_SalesHistory
WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [BeginDate] And [EndDate]) AND ((dbo_SO_SalesHistory.CustomerNo)="M"));
这是我的查询 运行 SQL: Image2
然后我试了UPDATE
PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
SELECT Sum(dbo_SO_SalesHistory.DollarsSold) AS SumOfDollarsSold
UPDATE [dbo_SO_SalesHistory.DollarsSold] SET [SumOfDollarsSold] = 0
FROM dbo_SO_SalesHistory
WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [BeginDate] And [EndDate]) AND ((dbo_SO_SalesHistory.CustomerNo)="M")) AND [SumOfDollarsSold] IS NULL;
它给我 The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
错误信息:Image3
任何关于我使用的任何方法的建议都将不胜感激。谢谢!
PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
SELECT IIF(ISNULL(Sum(dbo_SO_SalesHistory.DollarsSold)),0,Sum(dbo_SO_SalesHistory.DollarsSold)) AS SumOfDollarsSold
FROM dbo_SO_SalesHistory
WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [BeginDate] And [EndDate]) AND ((dbo_SO_SalesHistory.CustomerNo)="M"))
您的查询在执行时不知道列 SumOfDollarsSold
是什么。因此,您要么必须将其设为 subquery
并测试一个值,要么您可以在 IIf
语句中使用实际的聚合函数。
或者为了显示目的更好的方法是 FORMAT()
函数,但请注意,该数字实际上是一个字符串。我不太记得访问的实现,但它可能是这样的:
PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
SELECT FORMAT(Sum(dbo_SO_SalesHistory.DollarsSold)),0) AS SumOfDollarsSold
FROM dbo_SO_SalesHistory
WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [BeginDate] And [EndDate]) AND ((dbo_SO_SalesHistory.CustomerNo)="M"))
我的好参考是How to replace blank (null ) values with 0 for all records?
目标 :我有空白查询输出。 Image0 我希望打印出 0。
问题:当我尝试IIF Isnull
时,我得到一个提示信息框输入参数值,这是我不想看到的。 Image1
PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
SELECT Sum(dbo_SO_SalesHistory.DollarsSold) AS SumOfDollarsSold, IIF(ISNULL([SumOfDollarsSold]), 0, [SumOfDollarsSold])
FROM dbo_SO_SalesHistory
WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [BeginDate] And [EndDate]) AND ((dbo_SO_SalesHistory.CustomerNo)="M"));
这是我的查询 运行 SQL: Image2
然后我试了UPDATE
PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
SELECT Sum(dbo_SO_SalesHistory.DollarsSold) AS SumOfDollarsSold
UPDATE [dbo_SO_SalesHistory.DollarsSold] SET [SumOfDollarsSold] = 0
FROM dbo_SO_SalesHistory
WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [BeginDate] And [EndDate]) AND ((dbo_SO_SalesHistory.CustomerNo)="M")) AND [SumOfDollarsSold] IS NULL;
它给我 The SELECT statement includes a reserved word or an argument name that is misspelled or missing, or the punctuation is incorrect.
错误信息:Image3
任何关于我使用的任何方法的建议都将不胜感激。谢谢!
PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
SELECT IIF(ISNULL(Sum(dbo_SO_SalesHistory.DollarsSold)),0,Sum(dbo_SO_SalesHistory.DollarsSold)) AS SumOfDollarsSold
FROM dbo_SO_SalesHistory
WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [BeginDate] And [EndDate]) AND ((dbo_SO_SalesHistory.CustomerNo)="M"))
您的查询在执行时不知道列 SumOfDollarsSold
是什么。因此,您要么必须将其设为 subquery
并测试一个值,要么您可以在 IIf
语句中使用实际的聚合函数。
或者为了显示目的更好的方法是 FORMAT()
函数,但请注意,该数字实际上是一个字符串。我不太记得访问的实现,但它可能是这样的:
PARAMETERS [BeginDate] DateTime, [EndDate] DateTime;
SELECT FORMAT(Sum(dbo_SO_SalesHistory.DollarsSold)),0) AS SumOfDollarsSold
FROM dbo_SO_SalesHistory
WHERE (((dbo_SO_SalesHistory.InvoiceDate) Between [BeginDate] And [EndDate]) AND ((dbo_SO_SalesHistory.CustomerNo)="M"))