Sideway
output.to from Sideway
Draft for Information Only

Content

Select Clause
 Syntax
 Parts
 Remarks
 Example
 See also
 Source/Reference

Select Clause

Defines the result of a query.

Syntax

Select [ var1 = ] fieldName1 [, [ var2 = ] fieldName2 [...] ]  

Parts

TermDefinition var1Optional. An alias that can be used to reference the results of the column expression. fieldName1Required. The name of the field to return in the query result.

Remarks

You can use the Select clause to define the results to return from a query. This enables you to either define the members of a new anonymous type that is created by a query, or to target the members of a named type that is returned by a query. The Select clause is not required for a query. If no Select clause is specified, the query will return a type based on all members of the range variables identified for the current scope. For more information, see Anonymous Types. When a query creates a named type, it will return a result of type IEnumerable<T> where T is the created type. The Select clause can reference any variables in the current scope. This includes range variables identified in the From clause (or From clauses). It also includes any new variables created with an alias by the Aggregate, Let, Group By, or Group Join clauses, or variables from a previous Select clause in the query expression. The Select clause can also include static values. For example, the following code example shows a query expression in which the Select clause defines the query result as a new anonymous type with four members: ProductName, Price, Discount, and DiscountedPrice. The ProductName and Price member values are taken from the product range variable that is defined in the From clause. The DiscountedPrice member value is calculated in the Let clause. The Discount member is a static value.
' 10% discount 
Dim discount_10 = 0.1
Dim priceList =
  From product In products
  Let DiscountedPrice = product.UnitPrice * (1 - discount_10)
  Select product.ProductName, Price = product.UnitPrice,
  Discount = discount_10, DiscountedPrice
The Select clause introduces a new set of range variables for subsequent query clauses, and previous range variables are no longer in scope. The last Select clause in a query expression determines the return value of the query. For example, the following query returns the company name and order ID for every customer order for which the total exceeds 500. The first Select clause identifies the range variables for the Where clause and the second Select clause. The second Select clause identifies the values returned by the query as a new anonymous type.
Dim customerList = From cust In customers, ord In cust.Orders
                   Select Name = cust.CompanyName,
                          Total = ord.Total, ord.OrderID
                   Where Total > 500
                   Select Name, OrderID
If the Select clause identifies a single item to return, the query expression returns a collection of the type of that single item. If the Select clause identifies multiple items to return, the query expression returns a collection of a new anonymous type, based on the selected items. For example, the following two queries return collections of two different types based on the Select clause. The first query returns a collection of company names as strings. The second query returns a collection of Customer objects populated with the company names and address information.
Dim customerNames = From cust In customers
                    Select cust.CompanyName

Dim customerInfo As IEnumerable(Of Customer) =
  From cust In customers
  Select New Customer With {.CompanyName = cust.CompanyName,
                             .Address = cust.Address,
                             .City = cust.City,
                             .Region = cust.Region,
                             .Country = cust.Country}

Example

The following query expression uses a From clause to declare a range variable cust for the customers collection. The Select clause selects the customer name and ID value and populates the CompanyName and CustomerID columns of the new range variable. The For Each statement loops over each returned object and displays the CompanyName and CustomerID columns for each record.
Sub SelectCustomerNameAndId(ByVal customers() As Customer)
    Dim nameIds = From cust In customers
                  Select cust.CompanyName, cust.CustomerID
    For Each nameId In nameIds
        Console.WriteLine(nameId.CompanyName & ": " & nameId.CustomerID)
    Next
End Sub

See also

Source/Reference


©sideway

ID: 210500018 Last Updated: 5/18/2021 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close

Latest Updated LinksValid XHTML 1.0 Transitional Valid CSS!Nu Html Checker Firefox53 Chromena IExplorerna
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 339

Reference 79

Computer

Hardware 249

Software

Application 213

Digitization 32

Latex 52

Manim 205

KB 1

Numeric 19

Programming

Web 289

Unicode 504

HTML 66

CSS 65

SVG 46

ASP.NET 270

OS 429

DeskTop 7

Python 72

Knowledge

Mathematics

Formulas 8

Algebra 84

Number Theory 206

Trigonometry 31

Geometry 34

Coordinate Geometry 2

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Natural Sciences

Matter 1

Electric 27

Biology 1

Geography 1


Copyright © 2000-2024 Sideway . All rights reserved Disclaimers last modified on 06 September 2019