Note that the use of the Case function in transact-SQL leads to different result sets.

Source: Internet
Author: User

Select a. GCMC as fname, A. jsdw as fowner,Case
When B. FID is null then-1 else B. FID end as farea,

A. content as fcontent, A. updatetime as ftime, null as fhref, A. deleted as fisdel

From z_bidding a left join ccic_area B on charindex (B. fname, A. areaid)> 0

And

Select a. GCMC as fname, A. jsdw as fowner,Case B. FID
When null then-1 else B. FID end as farea
,
A. content as fcontent, A. updatetime as ftime, null as fhref, A. deleted as fisdel

From z_bidding a left join ccic_area B on charindex (B. fname, A. areaid)> 0

The execution results are different.

A. Easy to use Case Function Select Statement

Use Adventureworks;
Go
Select Productnumber, category =
Case Productline
When   ' R '   Then   ' Road '
When   ' M '   Then   ' Mountain '
When   ' T '   Then   ' Touring '
When   ' S '   Then   ' Other sale items '
Else   ' Not for sale '
End ,
Name
From Production. Product
Order   By Productnumber;
Go


B. Easy to use Case Functions and Case Search function Select Statement

Use Adventureworks;
Go
Select Productnumber, name, ' Price Range '   =  
Case  
When Listprice = 0   Then   ' MFG item-not for resale '
When Listprice <   50   Then   ' Under $50 '
When Listprice > =   50   And Listprice <   250   Then   ' Under$ 250 '
When Listprice > =   250   And Listprice <   1000   Then   ' Under$ 1000 '
Else   ' Over $1000. '
End
From Production. Product
Order   By Productnumber;
Go

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.