Domanda

With years of handling special cases in some of my queries, I'm curious if there is a simlified version of the CASE logic below:

SELECT
  CASE WHEN AverageRate < 0.1 THEN 0 ELSE AverageRate END AS [AverageRate]
FROM AdventureWorks.Sales.CurrencyRate

Ideally, it would behave very similarly to ISNULL, but allows for an additional input for the conditional statement.

I know it would be relatively easy to roll my own function, but I was wondering if there was something built in that I could tap.

Thanks.

Mark

È stato utile?

Soluzione

SQL Server 2012 is likely to introduce the IIF function. I say 'likely' because we can't be sure until the release version is shipped. De-facto, it is supported in current RC's.
As for the earlier versions of SQL Server, there are no such built-in shorthand approaches.

Altri suggerimenti

I've been around sql server quite a few years and haven't come across any shorter clause to perform conditional check.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top