Use Case? What is SQL ?? Arrange

Source: Internet
Author: User
SQL Server (WINDOWS powerful database platform) on? ? Expected? Yes? Use ?? So the user? Use Order clause? Do? Material arrangement, in? Article? Why ?? Step by step? How to Use Case? Do ?? Is the OrderBy clause sorted first? Look? Generally, the Select? If, in? Example of an article? Use sqlserver (WI

SQL server (a powerful database platform on WINDOWS? ? Expected? Yes? Use ?? So the user? Use Order clause? Do? Material arrangement, in? Article? Why ?? Step by step? How to Use Case? Do ?? Sort Order By clause first? Look? Generally, the Select? If, in? Example of an article? Use SQL server (WI


SQL server (a powerful database platform on WINDOWS? ? Expected? Yes? Use ?? So the user? Use Order clause? Do? Raw Materials Arrange, In? Article? Why ?? Step by step? How to Use Case? Do ?? Of Arrange

Order By clause

First? Look? Generally, the Select? If, in? Example of an article? What is the north of SQL server (a powerful database platform on WINDOWS ?? Material ?, ? ? Query Analyzer ,? Line

Use Northwind
Go
Select CompanyName, ContactName, ContactTitle
From MERs

? Row? What is the possible result? Expected? Entered ??? ArrangeWhere are you going to take care of yourself ??? You need to use the Order By clause, for example? Previous? For example, Which of the following is your company name? What should I do?

Select CompanyName, ContactName, ContactTitle
From MERs
Order By CompanyName

Case? Description

Case? ? Use? Control the flow of the program. ExploitationCase? ? Do T-SQL ?? Control ,? Look? Case? Method

Case
When Then
[... N]
[Else ]

Just look? Method ?, ? Using one? Example ??? What about the same region? Is it north ?? Material ?, False? Me? Yes ??? (Employees )? In the table? Call to change to another server? Type, you can do it

Select FirstName, TitleOfCourtesy, CourtesyInTC =
Case TitleOfCourtesy
When 'Ms. 'Then 'watergirl'
When 'Dr. 'then' doctor Bo'
When 'Mr. 'then' xianzai'
When 'Mrs. 'then' Ms'
Else 'Mr/Miss'
End
From employees

?? Arrange

Have you understood the basics? France? You can? Start ?? Press ExploitationOrder By plus Case? ? Do ?? ? Raw Materials Arrange

Declare @ OrderKey TinyInt
Set @ OrderKey = 2
 
Select CompanyName, ContactName, ContactTitle
From MERs
Order By Case
When @ OrderKey = 1 Then CompanyName
When @ OrderKey = 2 Then ContactName
Else ContactTitle
End

No ??? Like? Not quite? Used, at least in ASP, so next? Me? Do one ??? Program

Create Procedure sp_SelectCustomersDynamicOrder
@ OrderKey = Null
As
Select CompanyName, ContactName, ContactTitle
From MERs
Order By Case
When @ OrderKey = 1 Then CompanyName
When @ OrderKey = 2 Then ContactName
Else ContactTitle
End

? You can call directly ?? Stored Procedure

Exec sp_SelectCustomersDynamicOrder
Exec sp_SelectCustomersDynamicOrder 1
Exec sp_SelectCustomersDynamicOrder 2

Is it more friendly?

Hope? Article? You have? Help!
   
Related Article

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.