WHEN bieuthuc_1 THEN ketqua_1 WHEN bieuthuc_2 THEN ketqua_2 . WHEN bieuthuc_n THEN ketqua_n ELSE ketqua_khac END
Or Searched CASE
CASE WHEN dieukien_1 THEN ketqua_1 WHEN dieukien_2 THEN ketqua_2 . WHEN dieukien_n THEN ketqua_n ELSE ketqua_khac END
Parameters :
bieuthuc_dauvao: The expression will be compared to each value provided.
bieuthuc_1, bieuthuc_2, bieuthuc_n: expressions will be used to compare in turn with the input expression. When an expression matches bieuthu_dauvao, CASE will execute the next statement and no further comparison.
dieukien_1, dieukien_2, dieukien_n : conditions reviewed, approved in the order listed. When a condition is determined to be true, CASE returns the result and no further conditions are evaluated. All conditions must be the same data type.
ketqua_1, ketqua_2, ketqua_n : the result returned after considering the condition is true. All values must be the same data type.
Note :
If no match is found for TRUE, the CASE statement will return the result in the ELSE clause.
If there is no ELSE clause and there is no TRUE condition then the CASE statement will return NULL.
Conditions are evaluated in the order listed. When a condition is determined to be true, the CASE statement returns the result and no further conditions are evaluated.
CASE can be used in later versions of SQL Server: SQL Server 2017, SQL Server 2016, SQL Server 2014, SQL Server 2012, SQL Server 2008 R2, SQL Server 2008, and SQL Server 2005.
For example
Take a look and explore some examples of CASE statements in SQL Server.
Example 1: Simple CASE
Suppose you need to check the section of the TipsMake.com website, based on the Code column of the conversion table:
If Code = '01' is 'Laptrinh-TipsMake.com'.
If Code = '02' is 'Congnghe-TipsMake.com'.
If Code = '03' is 'Cuocsong-TipsMake.com'.
On the contrary, that is not from 1 to 3 then in the section 'Khoahoc-TipsMake.com'.
SELECT tenchuyenmuc, Code (CASE code WHEN 01 THEN 'Laptrinh-TipsMake.com' WHEN 02 THEN 'Congnghe-TipsMake.com' WHEN 03 THEN 'Cuocsong-TipsMake.com' ELSE 'Khoahoc-TipsMake.com' END) AS Chuyenmuc FROM chuyenmuc ORDER BY Code
SELECT tenchuyenmuc, CASE WHEN code = 01 THEN 'Laptrinh-TipsMake.com' WHEN code = 02 THEN 'Congnghe-TipsMake.com' WHEN code = 03 THEN 'Cuocsong-TipsMake.com' ELSE 'Khoahoc-TipsMake.com' END FROM chuyenmuc;
You may also not use ELSE conditions like this:
SELECT tenchuyenmuc, Code (CASE code WHEN 01 THEN 'Laptrinh-TipsMake.com' WHEN 02 THEN 'Congnghe-TipsMake.com' WHEN 03 THEN 'Cuocsong-TipsMake.com' END) AS Chuyenmuc FROM chuyenmuc ORDER BY Code
Or:
SELECT tenchuyenmuc, CASE WHEN code = 01 THEN 'Laptrinh-TipsMake.com' WHEN code = 02 THEN 'Congnghe-TipsMake.com' WHEN code = 03 THEN 'Cuocsong-TipsMake.com' END FROM chuyenmuc;
When the ELSE clause is omitted, if no condition is true, the CASE statement returns NULL.
Example 3: Comparing two conditions
Here is an example that illustrates how to use CASE statements to compare different conditions:
SELECT CASE WHEN code < 2 THEN 'Laptrinh-TipsMake.com' WHEN code = 2 THEN 'Congnghe-TipsMake.com' END FROM chuyenmuc;
Remember that the conditions are compared in turn in the order listed. When a condition is determined to be true, the CASE statement will return the result immediately and no other conditions will be evaluated. So you need to be careful when choosing the order that lists your conditions.
See more specific examples of CASE functions in SQL Server
Previous article: Check version information in SQL Server
network management documentation server 2003 as details of how to install, create a companion server in case the main server is malfunctioning, create a domain, join the client to the domain, the conection {remote desktop from the client data to server}, set adsl router parameters to server, turn off 1 working machine immediately.
by default, your computer will automatically obtain dns information from your isp (isp). sometimes, dns servers are unstable and you are blocked from accessing certain websites. or the default dns server is blocked by some websites for a number of reasons. in this case you should change the dns server with the free public dns server.
it is quite hard to write a really good artist statement, even if you're a good writer. the statement accompanies a piece or set of work you've painted, drawn, photographed, created, and it must sum up such elements as motivation,...
there are many ways to connect to the ftp server and access the content in it. however, the simplest way is to use internet explorer. the ftp connection method via internet explorer is used in case you only want to download or view files stored on ftp public server (with incognito mode).
this article will show you in detail how to use the nullif function handler in sql server with specific syntax and examples to better visualize and capture functions.
in the following article, we will help you distinguish some basic differences between two delete syntax and truncate table in microsoft sql server application. basically, both of these statements help us to remove the data, but in essence it is not so.
the group by clause in sql server (transact-sql) is used in the select statement to retrieve data from multiple records and result groups into 1 or more columns.
the isnumeric function in sql server checks whether the value of the passed expression is a valid numeric value, if there is isnumeric returns 1, otherwise it returns 0.
you have probably seen that the terms web server and app server are often used interchangeably as if they are related to the same thing and also facilitate the website to function properly. but in reality, they are not the same.