引自MSDN的Select语法结构(为了方便自己查找:))
2009-09-24 19:37
573 查看
引自MSDN:http://msdn.microsoft.com/en-us/library/aa656402.aspx
Select Statement Syntax
Keywords Used in the Select Syntax
Select Statement Syntax
SelectStatement | = | selectParameters |
Parameters | [[FindOptions ] [FieldList from]]TableBufferVariable [IndexClause ] [Options ] [WhereClause ] [JoinClause ] | |
FindOptions | = | crossCompany| reverse| firstFast| [ firstOnly| firstOnly10| firstOnly100| firstOnly1000] | forUpdate| noFetch| [ forcePlaceholders| forceLiterals] | forceselectorder| forceNestedLoop| repeatableRead |
FieldList | = | Field { ,Field }| * |
Field | = | Aggregate (FieldIdentifier ) |FieldIdentifier |
Aggregate | = | sum| avg| minof| maxof| count |
Options | = | [order by, group by ,FieldIdentifier [asc| desc]{ ,FieldIdentifier [asc| desc]}]| [IndexClause ] |
IndexClause | = | indexIndexName | indexhintIndexName |
WhereClause | = | whereExpression |
JoinClause | = | [exists| notexists| outer] joinParameters |
Keywords Used in the Select Syntax
Keyword | Description | Example |
---|---|---|
asc | An option on the order byor group byclause. The sorting is ascending. (Sort is ascending by default.) | select * from custTable order by Name asc; |
avg | Returns the average of the fields. | CustTable custTable; ; select avg(value) from custTable; print custTable.value; |
count | Returns the number of records. | CustTable xCT; int64 iCountRows; ; Select COUNT(RecID) from xCT; iCountRows = xCT.RecID; |
crossCompany | Returns data for all companies that the user is authorized to read from. (A containercan be added to reduce the number of companies involved.) | CustTable custTable; container conCompanies = ['dat','dmo']; ; select crossCompany :conCompanies * from custTable; |
desc | An option on the order byor group byclause. The sorting is descending. | select * from custTable order by Name desc; |
exists | A method that returns a Boolean value and a joinclause. | while select AccountNum, Name from custTable order by AccountNum exists join* from ctr where(ctr.AccountNum == custTable.AccountNum) |
firstFast | A priority hint. The first row appears more quickly but the total return time for this option might be slower. The firstFasthint is automatically issued from all forms, but is rarely used directly from X++. | select firstFast custTable order by AccountNum; |
firstOnly | Speeds up the fetch. Instructs MorphX to fetch only the first record. | static InventTable find( ItemId itemId, boolean update = false) { InventTable inventTable; ; inventTable.selectForUpdate (update); if (itemId) { select firstonly inventTable indexhint ItemIdx whereinventTable.itemId == itemId; } return inventTable; } |
firstOnly10 | Same as firstOnly, except returns 10 rows instead of one. | |
firstOnly100 | Same as firstOnly, except returns 100 rows instead of one. | |
firstOnly1000 | Same as firstOnly, except returns 1000 rows instead of one. | |
forceLiterals | Note You are advised not to use the forceLiterals keyword in X++ selectstatements, because it could expose code to an SQL injection security threat. forceLiterals instructs the kernel to reveal the actual values that are used in whereclauses to the Microsoft SQL Server database at the time of optimization. forceLiterals and forcePlaceholders are mutually exclusive. | |
forceNestedLoop | Forces the Microsoft SQL Server database to use a nested-loop algorithm to process a particular SQL statement containing a joinalgorithm. This means that a record from the first table is fetched before any records from the second table are fetched. Typically, other joinalgorithms, such as hash-joins and merge-joins, would be considered. This keyword is often combined with the forceSelectOrder keyword. | while select forceSelectOrder forceNestedLoop inventTransThis indexhint TransIdIdx whereinventTransThis.InventTransId == inventTrans.InventTransId && inventTransThis.StatusIssue <= StatusIssue::ReservOrdered |
forcePlaceholders | Instructs the kernel not to reveal the actual values used in whereclauses to the SQL Server database at the time of optimization. This is the default in all statements that are not joinstatements. The advantage of using this keyword is that the kernel can reuse the access plan for other similar statements with other search values. The disadvantage is that the access plan is computed without taking into consideration that data distribution might not be even. The access plan is an on-average access plan. forcePlaceholders and forceLiterals are mutually exclusive. | static void forcePlaceHoldersExample(Args _args) { SalesTable salesTable; SalesLine salesLine; ; while select forcePlaceholders salesLine joinsalesTable wheresalesTable.SalesId == salesLine.SalesId && salesTable.SalesId == '10' { //more code } } |
forceSelectOrder | Forces the SQL Server database to access the tables in a joinin the specified order. If two tables are joined, the first table in the statement is always accessed first. This keyword is often combined with the forceNestedLoop keyword. | display ForecastHasPurch hasForecastPurch() { ForecastPurch forecastPurch; InventDim inventDim; ; select firstOnly forcePlaceholders forceSelectOrder recId from forecastPurch indexhint ItemIdx whereforecastPurch.itemId == this.itemId exists joininventDim indexhint DimIdIdx whereinventDim.inventDimId == forecastPurch.inventDimId && inventDim.configId == this.configId; return forecastPurch.recId; } |
forUpdate | Selects records exclusively for update. Depending on the underlying database, the records may be locked for other users. | ttsBegin; while select forUpdate ledgerJournalTrans indexhint NumVoucherIdx whereledgerJournalTrans.journalNum == _journalNum && ledgerJournalTrans.voucher == _voucher { ledgerJournalTrans.doDelete(); counter++; } if (counter && ledgerJournalTable.journalType != LedgerJournalType::Periodic) { NumberSeq::release( ledgerJournalTable.voucherSeries, _voucher); } ttsCommit; |
group by | Instructs the database to group selected records by fields. | CustTable custTable; ; while select sum(CreditMax) from custTable group by CustGroup { print custTable.CustGroup, " ",custTable.CreditMax; } |
index | Instructs the database to sort the selected records as defined by the index. | CustTable custTable; ; while select AccountNum, Name from custTable indexAccountIdx { print custTable.AccountNum, " ", custTable.Name; } |
indexhint | Gives the database a hint to use this indexto sort the selected records as defined by the index. The database can ignore the hint. Note A wrong indexhint can have a big performance impact. Index hints should only be applied to SQL statements that do not have dynamic whereclauses or order byclauses, and wherethe effect of the hint can be verified. | while select forUpdate ledgerJournalTrans indexhint NumVoucherIdx whereledgerJournalTrans.journalNum == _journalNum |
join | Used to jointables on a column that is common to both tables. Reduces the number of SQL statements that are needed if you want to loop through a table and update transactions in a related table. For example, if you process 500 records in a table, and want to update related records in another table, and use a nested while selectto do this, there will be 501 trips to the database. If you use a join, there will be a single trip to the database. | while select ledgerTable joinledgerTrans whereledgerTrans.accountNum == ledgerTable.accountNum { amountMST += ledgerTrans.amountMST; } |
maxof | Returns the maximum of the fields. | CustTable custTable; ; select maxof(CreditMax) from custTable; |
minof | Returns the minimum of the fields. | CustTable custTable; ; select minof(CreditMax) from custTable; |
noFetch | Indicates that no records are to be fetched at present. This is typically used when the result of the select is passed on to another application object, for example, a query that performs the actual fetch. | select noFetch custTable order by AccountNum |
notExists | Chosen only if there are no posts. | while select AccountNum, Name from custTable order by AccountNum notExists join* from ctr where(ctr.AccountNum == custTable.AccountNum) |
optimisticLock | Forces a statement to run with Optimistic Concurrency Control even if a different value is set on the table. For more information, see Optimistic Concurrency Control. | select optimisticLock custTable wherecustTable.AccountNum > '1000' |
order by | Instructs the database to sort the selected records by fields in the order bylist. | select * from custTable order by accountNum desc wherecustTable.AccountNum > "100"; |
outer | outer join. Can typically display all rows that both do and do not meet the conditions. An outer join can display all non-matching rows from either the first-named table or second-named table, or from both tables together. | while select AccountNum, Name from custTable order by AccountNum outer join* from ctr where(ctr.AccountNum == custTable.AccountNum) |
pessimisticLock | Forces a statement to run with Pessimistic Concurrency Control even if a different value is set on the table. For more information, see Optimistic Concurrency Control. | select pessimisticLock custTable wherecustTable.AccountNum > '1000' |
repeatableRead | Specifies that no other transactions can modify data that has been read by logic inside the current transaction, until after the current transaction completes. An explicit transaction completes at either ttsAbort or at the outermost ttsCommit. For a stand-alone select statement, the transaction duration is the duration of the select command. However, the database sometimes enforces the equivalent of repeatableRead in individual select statements even without this keyword appearing in your X++ code (depending on how the database decides to scan the tables). | For more information, see the documentation for the underlying relational database product. |
reverse | Records are returned in reverse order. | select reverse custTable order by AccountNum; |
sum | Returns the sum of the fields. Can be used to sum all accounts, order lines, and so on. | CustTable custTable; ; select sum(CreditMax) from custTable; |
相关文章推荐
- atoi itoa 为了自己以后查找方便
- C语言运算符优先级记录-为了自己查找方便
- C语言运算符优先级记录-为了自己查找方便
- log4j 很详细(为了方便以后自己 mark)
- 网络查找文档比自己电脑上还方便?[转帖]
- ajax select option 数据。为了下次方便信手拈来!!
- 【Kris专题】android Style 小结---kris写的,我复制来就是为了自己查找方便
- Java 多线程编程,方便自己查找
- 关于 jquery select 的一些记录,主要方便自己查看
- Windows 7下OpenGL如何配置(网上有教程,这里做部分修改,也是为了方便自己以后使用)
- VHDL常见的语法结构,粘贴此处方便查询
- OC 函数式编程 (非原创 为了方便查找 所以设置为原创)
- 为了方便维护,以后无论如何,数据库操作一定使用封装的强类型,或者自己封装的数据操作类。后记,使用分布式查询解决多个数据库之间的查询操作。
- 自己制作一个链表用来存储列表信息,并查找当前id信息,找上一条信息,下一条信息(信息浏览的时候方便使用)
- 关于orcale的数据库脚本,记录下来,方便自己以后用到查找
- 杭电ACM试题分类 (只是为了自己看着方便)
- 经典SQL语句大全 收集别人的主要是为了学习的时候查找方便
- ASP.NET 4【MSDN参考文档-方便自己查阅】
- ASP.NET 4【MSDN参考文档-方便自己查阅】
- Java 多线程编程,方便自己查找