

sql-server – 如果参数为null,则SQL select all all返回特定项
以下为 快照 页面,建议前往来源网站查看,会有更好的阅读体验。
原文链接: https://codeday.me/bug/20190112/508961.html?amp%3Butm_medium=referral
有没有办法编写以下脚本,以便在ProductID变量为null时返回所有产品?并在产品不为空时返回特定产品.
到目前为止我所拥有的:
DECLARE @productID INT = NULL SELECT ProductID, ProductName, ProductDesc FROM product WHERE ProductID = @productID
用例陈述:
SELECT ProductID, ProductName,ProductDesc FROM product WHERE ProductID = CASE WHEN @productID IS NULL THEN ProductID ELSE @productID END
或者IIF()函数,如果您使用的是SQL Server 2012:
SELECT ProductID, ProductName,ProductDesc FROM product WHERE ProductID =IIF(@productID IS NULL, ProductID, @productID )
翻译自:https://stackoverflow.com/questions/19357990/sql-select-all-if-parameter-is-null-else-return-specific-item
猜你喜欢
-
12
在上篇文章
-
2
linux C语言多线程编程,如何传入参数,如何获得返回值 发表于 2018-08-07 2...
-
1
nanopass之六--处理调用参数和返回值2015-03-11Scheme子集6* 5.1. verify-scheme 5.2. remove-complex-opera* 5.3. flatten-set!* 5.4. impose-calling-conventions* 5.5. ex...
-
2
Using IDENTITY function with SELECT statement in SQL Server In MS BOL for IDENTITY columns it is mentioned that [link]: “It creates an...
-
0
Select all parents or children in the same SQL Server table relationship advertisements SQL developers, I have a badly planned database as tas...
-
67
reddit: the front page of the internet
-
98
-
92
At first glance, null and undefined may seem the same, but they are far from it. This article will explore the differences and similarities between null and undefined in JavaScript. In JavaScript…
-
62
理解JavaScript中null、undefined和NaN
-
64
How to keep your terminal and vim themes in sync
关于极客头条
聚合每日国内外有价值,有趣的链接。