Several tips for SQL Server

Source: Internet
Author: User
Tags count sql query
server|sqlserver| tips 1. To reactivate a field (from 1 to n):D eclare @i intset @i = 0Update Table1 Set @i = @i + 1,field1 = @i2. Ranking by grade update into Performance table set A. Rank = (Select Count (*) + 1From score sheet bwhere a. Total score < b. Total score) from A3. Query the external database Select a.*from OpenRowSet (' Microsoft. jet.oledb.4.0 ', ' C:\test.mdb '; Admin '; ', Table1 A4. Query Excel File Select * from OpenDataSource (' microsoft.jet.oledb.4.0 ', ' Data source= ' C:\Test.xls '); User id=admin; password=; Extended properties=excel 8.0 ') ... Sheet1$5. Specifying collations in a query select * from Table1 orders by Field1 COLLATE Chinese_prc_bin Why do you want to specify a collation? See also: http://www.delphibbs.com In the/delphibbs/dispq.asp?lid=1633985 example, check to see if the specified user exists in the Pub_users table in the database: Select Count (*) from pub_users Where [username]= ' Admin ' and [password]= ' AAA ' COLLATE chinese_prc_bin default comparisons are case-insensitive, and if you do not add COLLATE chinese_prc_bin, then the password AAA and AAA are equivalent, This, of course, does not match the reality. Note that the collation is specified for each condition, and the user name is case-insensitive in the example above. 6.Order by a trick order by can specify a column without specifying a column name, which is useful in the following example (note that the third column does not specify an alias) Select a . Id,a.name, (Select Count (*) from TableB b Where a.id=b.pid) from TableA a order by 3

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.