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!