Include Method

Applies to:  SqlQueryBuilder object
See also:  Method and Function Index

Includes a table in the query.

Syntax:

object.Include Table /* The name of the table that is to be added to the query. */ As , [RelationType /* The type of join to be performed. Must be one of BelongsTo~ HasMany~ Inherit~ IsOrthogonalTo. */ /* The JoinType parameter describes the relationship between the records in the newly joined table and records in the table to which it is to be joined. The correct choice of JoinType will depend on the order in which tables are joined in addition to the database design. */ /* The JoinType parameter is ignored for the first table that is joined to a query. */ /* For example~ in a database that describes a collection of music CDs~ an An Artist can have many Albums~ and a Song belongs to an Album. */ /* Assuming an obvious naming convention~ a query can be built that joins the Album table with the Artist and Song tables thus: */ /* Dim sql As SqlBuilder Set sql = MakeSqlBuilder sql.Join "Album"~ ~ ~ "AlbumId" 'JoinType should be omitted for the first table added to a query. sql.Join "Artist"~ HasMany~ ~ "ArtistId"~ "Album" sql.Join "Song"~ BelongsTo~ ~ "SongId"~ "Album" The SqlBuilder object can build more efficient queries if all of the joins in a query are BelongsTo~ or if all of the joins in a query are HasMany. The relationshp between Artists and Albums is described above as "An Artist can have many Albums"~ but that relationship could also be described as "An Album belongs to an Artist". Dim sql As SqlBuilder Set sql = MakeSqlBuilder sql.Join "Song"~ ~ ~ "SongId" sql.Join "Album"~ BelongsTo~ ~ "AlbumId"~ "Artist" sql.Join "Artist"~ BelongsTo~ ~ "ArtistId"~ "Album" In order to use the same JoinType for all of the joins in a query~ it is usually necessary to carefully plan the order in which tables will be added to the query. Provided that the Primary Key columns of each table are named according to the pattern Id~ the PrimaryKey parameter can be omitted. If each of the joins in a query are BelongsTo~ the JoinType parameter can also be omitted as BelongsTo is the default JoinType. Dim sql As SqlBuilder Set sql = MakeSqlBuilder sql.Join "Song" sql.Join "Album"~ ~ ~ "Song" sql.Join "Artist"~ ~ ~ "Album" The SqlBuilder object has another useful default behaviour: On second and subsequent calls to the Join method~ if the JoinTo parameter is not specified~ it will assume that the newly joined table is to be joined to the table that was most recently joined. The preceding example can therefore be simplified even further: Dim sql As SqlBuilder Set sql = MakeSqlBulider sql.Join "Song" sql.Join "Album" sql.join "Artist" */ As = 0], [RelatedTo /* The name of the previously joined table to which the new table will be joined. QueryBuilder's can use the JoinTo parameter to build a join condition that will be used in the event that the JoinCondition parameter is omitted. */ /* If both the JoinTo and JoinCondition parameters are omitted~ the newly joined table will be joined to the previously joined table which was most recently added to the query. */ As ], [Alias /* The alias that will be used for the newly added table. If omitted~ no alias will be used. */ As ], [PrimaryKey /* The name of the primary key column of the newly added table. QueryBuilder's can use the PrimaryKey parameter to build a join condition that will be used in the event that the JoinCondition parameter is omitted. */ /* If the PrimaryKey and JoinCondition parameters are both omitted~ the primary key will be assumed to be the concatenation of the table's name~ and the letters "Id". */ /* If the newly joined table has a composite primary key~ the PrimaryKey parameter should be omitted and the JoinCondition should be explicitly specified. */ As ], [ForeignKey /* The foreign key for the newly joined table in the previously joined table to which the new table will be joined. QueryBuilder's can use the ForeignKey parameter to build a join condition that will be used in the event that the JoinCondition parameter is omitted. */ /* If both the ForeignKey and JoinCondition parameters are omitted~ the QueryBuilder will assume a default foreign key column name~ based on JoinType. */ /* If JoinType is BelongsTo~ the default value for ForeignKey will be the name of the primary key column of the newly joined table. If JoinType is HasMany or Inherit~ the default value for ForeignKey will be the name of the PrimaryKey column of the table to which the new table is to be joined. If the JoinType is IsUnrelatedTo~ the ForeignKey parameter will be ignored. */ /* If the newly joined table has a composite primary key~ the PrimaryKey parameter should be omitted and the JoinCondition should be explicitly specified. */ As ], [JoinCondition /* The boolean condition that will be used to match records from the newly joined table with the records of another table previously added to the query. The JoinCondition parameter accepts either an Expression object or a String expression whose syntax is compatible with the QueryBuilder implementation being used.*/ /* In most cases~ the JoinCondition can be omitted and the QueryBuilder will build a join condition based on the information supplied in the preceding parameters. */ /* If a JoinCondition is explicitly specified~ the PrimaryKey~ JoinTo~ ForeignKey~ and JoinCondition parameters may be omitted. */ As ], [IncludeOrphans /* A flag indicating whether or not to include orphaned records. */ /* If IncludeOrphans = True~ and JoinType is either BelongsTo or Inherit~ records in the previously joined tables will be included regardless of whether there is a matching record in the newly joined table. */ /* If IncludeOrphans = True~ and JoinType = HasMany~ records in the newly joined table will be included regardless of whether there is a matching record in the previusly joined tables. */ /* If IncludeOrphans = False~ and JointType is BelongsTo~ Inherit~ or HasMany~ records will be discarded from both the newly and the previously joined tables~ where no match is found between the newly joined table and the table to which it is joined. */ /* If JoinType = IsUnrelatedTo~ the IncludeOrphans parameter will be ignored. */ As Boolean = True], [Select /* A comma separated list of fields in the newly joined table that will be added to the selection~ in the event that a SELECT~ SELECT INTO~ or INSERT INTO query is built. */ /* If an UPDATE query is built~ the Select parameter will be retrospectively ignored. */ /* If Select = ""~ no columns will be added to the selection. */ /* If Select = "*"~ all of the newly joined table's columns will be added to the selection. */ /* The Select parameter of the Join method can be used to add aliased or calculated fields by specifying such fields in the Select parameter using the appropriate SQL syntax. However~ the recommended technique for adding aliased or calculated fields is to use the Select method~ which can be used in conjunction with an Expression object to add calculated fields in an SQL dialect neutral manner. */ As String = ""], [DeSelect /* A comma separated list of fields in the newly joined table that will be removed from the selection~ in the event that a SELECT~ SELECT INTO~ or INSERT INTO query is built. */ /* If a field is named in both the Select and DeSelect parameters~ that field will not be included in the selection. */ /* If a SELECT~ SELECT INTO~ or INSERT INTO query is built~ the resulting query will exclude all columns that were excluded in the DeSelect parameter~ or by a separate call to the DeSelect method~ or which are foreign key fields with the same name as a primary key field included in the query. */ /* Fields in the newly joined table which share the same name as any non-primary-key fields of any table previously joined to the table~ should be excluded from the query~ either by being named in the DeSelect parameter~ or by a separate call to the DeSelect method. */ As String = ""]

The Include method syntax has these parts:

Part Description
object The name of an object in the Applies to list.
Table /* The name of the table that is to be added to the query. */ No help available for this parameter.
RelationType /* The type of join to be performed. Must be one of BelongsTo~ HasMany~ Inherit~ IsOrthogonalTo. */ /* The JoinType parameter describes the relationship between the records in the newly joined table and records in the table to which it is to be joined. The correct choice of JoinType will depend on the order in which tables are joined in addition to the database design. */ /* The JoinType parameter is ignored for the first table that is joined to a query. */ /* For example~ in a database that describes a collection of music CDs~ an An Artist can have many Albums~ and a Song belongs to an Album. */ /* Assuming an obvious naming convention~ a query can be built that joins the Album table with the Artist and Song tables thus: */ /* Dim sql As SqlBuilder Set sql = MakeSqlBuilder sql.Join "Album"~ ~ ~ "AlbumId" 'JoinType should be omitted for the first table added to a query. sql.Join "Artist"~ HasMany~ ~ "ArtistId"~ "Album" sql.Join "Song"~ BelongsTo~ ~ "SongId"~ "Album" The SqlBuilder object can build more efficient queries if all of the joins in a query are BelongsTo~ or if all of the joins in a query are HasMany. The relationshp between Artists and Albums is described above as "An Artist can have many Albums"~ but that relationship could also be described as "An Album belongs to an Artist". Dim sql As SqlBuilder Set sql = MakeSqlBuilder sql.Join "Song"~ ~ ~ "SongId" sql.Join "Album"~ BelongsTo~ ~ "AlbumId"~ "Artist" sql.Join "Artist"~ BelongsTo~ ~ "ArtistId"~ "Album" In order to use the same JoinType for all of the joins in a query~ it is usually necessary to carefully plan the order in which tables will be added to the query. Provided that the Primary Key columns of each table are named according to the pattern Id~ the PrimaryKey parameter can be omitted. If each of the joins in a query are BelongsTo~ the JoinType parameter can also be omitted as BelongsTo is the default JoinType. Dim sql As SqlBuilder Set sql = MakeSqlBuilder sql.Join "Song" sql.Join "Album"~ ~ ~ "Song" sql.Join "Artist"~ ~ ~ "Album" The SqlBuilder object has another useful default behaviour: On second and subsequent calls to the Join method~ if the JoinTo parameter is not specified~ it will assume that the newly joined table is to be joined to the table that was most recently joined. The preceding example can therefore be simplified even further: Dim sql As SqlBuilder Set sql = MakeSqlBulider sql.Join "Song" sql.Join "Album" sql.join "Artist" */ No help available for this parameter.
RelatedTo /* The name of the previously joined table to which the new table will be joined. QueryBuilder's can use the JoinTo parameter to build a join condition that will be used in the event that the JoinCondition parameter is omitted. */ /* If both the JoinTo and JoinCondition parameters are omitted~ the newly joined table will be joined to the previously joined table which was most recently added to the query. */ No help available for this parameter.
Alias /* The alias that will be used for the newly added table. If omitted~ no alias will be used. */ No help available for this parameter.
PrimaryKey /* The name of the primary key column of the newly added table. QueryBuilder's can use the PrimaryKey parameter to build a join condition that will be used in the event that the JoinCondition parameter is omitted. */ /* If the PrimaryKey and JoinCondition parameters are both omitted~ the primary key will be assumed to be the concatenation of the table's name~ and the letters "Id". */ /* If the newly joined table has a composite primary key~ the PrimaryKey parameter should be omitted and the JoinCondition should be explicitly specified. */ No help available for this parameter.
ForeignKey /* The foreign key for the newly joined table in the previously joined table to which the new table will be joined. QueryBuilder's can use the ForeignKey parameter to build a join condition that will be used in the event that the JoinCondition parameter is omitted. */ /* If both the ForeignKey and JoinCondition parameters are omitted~ the QueryBuilder will assume a default foreign key column name~ based on JoinType. */ /* If JoinType is BelongsTo~ the default value for ForeignKey will be the name of the primary key column of the newly joined table. If JoinType is HasMany or Inherit~ the default value for ForeignKey will be the name of the PrimaryKey column of the table to which the new table is to be joined. If the JoinType is IsUnrelatedTo~ the ForeignKey parameter will be ignored. */ /* If the newly joined table has a composite primary key~ the PrimaryKey parameter should be omitted and the JoinCondition should be explicitly specified. */ No help available for this parameter.
JoinCondition /* The boolean condition that will be used to match records from the newly joined table with the records of another table previously added to the query. The JoinCondition parameter accepts either an Expression object or a String expression whose syntax is compatible with the QueryBuilder implementation being used.*/ /* In most cases~ the JoinCondition can be omitted and the QueryBuilder will build a join condition based on the information supplied in the preceding parameters. */ /* If a JoinCondition is explicitly specified~ the PrimaryKey~ JoinTo~ ForeignKey~ and JoinCondition parameters may be omitted. */ No help available for this parameter.
IncludeOrphans /* A flag indicating whether or not to include orphaned records. */ /* If IncludeOrphans = True~ and JoinType is either BelongsTo or Inherit~ records in the previously joined tables will be included regardless of whether there is a matching record in the newly joined table. */ /* If IncludeOrphans = True~ and JoinType = HasMany~ records in the newly joined table will be included regardless of whether there is a matching record in the previusly joined tables. */ /* If IncludeOrphans = False~ and JointType is BelongsTo~ Inherit~ or HasMany~ records will be discarded from both the newly and the previously joined tables~ where no match is found between the newly joined table and the table to which it is joined. */ /* If JoinType = IsUnrelatedTo~ the IncludeOrphans parameter will be ignored. */ No help available for this parameter.
Select /* A comma separated list of fields in the newly joined table that will be added to the selection~ in the event that a SELECT~ SELECT INTO~ or INSERT INTO query is built. */ /* If an UPDATE query is built~ the Select parameter will be retrospectively ignored. */ /* If Select = ""~ no columns will be added to the selection. */ /* If Select = "*"~ all of the newly joined table's columns will be added to the selection. */ /* The Select parameter of the Join method can be used to add aliased or calculated fields by specifying such fields in the Select parameter using the appropriate SQL syntax. However~ the recommended technique for adding aliased or calculated fields is to use the Select method~ which can be used in conjunction with an Expression object to add calculated fields in an SQL dialect neutral manner. */ No help available for this parameter.
DeSelect /* A comma separated list of fields in the newly joined table that will be removed from the selection~ in the event that a SELECT~ SELECT INTO~ or INSERT INTO query is built. */ /* If a field is named in both the Select and DeSelect parameters~ that field will not be included in the selection. */ /* If a SELECT~ SELECT INTO~ or INSERT INTO query is built~ the resulting query will exclude all columns that were excluded in the DeSelect parameter~ or by a separate call to the DeSelect method~ or which are foreign key fields with the same name as a primary key field included in the query. */ /* Fields in the newly joined table which share the same name as any non-primary-key fields of any table previously joined to the table~ should be excluded from the query~ either by being named in the DeSelect parameter~ or by a separate call to the DeSelect method. */ No help available for this parameter.

Remarks:

Put more information here.

Home

Copyright and Disclaimer