SQL Server multi-Table update and sorting

Source: Internet
Author: User

1. You need to import an Excel file to the database during work, and modify the relevant table to import it without mentioning it. [item change price] The imported execl table sales?price commodity price list

Update salesprice price
Set salesprice price. saleprice = change the price of the product. New Sales Price
, Sales#price. costprice = change the price of the product. New cost price
From salesprice price, product price change
Where cast (sales=price. Sid as varchar (20) = cast (item change price. No. As varchar (20 ))

In this way, a table is modified with the conditions and values of another table.

2. Two Ways to insert data into a temporary table

(1) Select... into # O from table insert data to the temporary table

(2) Insert into # O Select... from table insert data to the temporary table

The two differences are as follows: (1) You do not need to create a table structure first. A temporary table automatically creates a temporary table of this type based on the select Field and its type. (2) You need to create a table structure first, before you can insert data to a temporary table

3. Notes for grouping SQL statements

(1) Select top 1 * from Table order by T1 DESC, T2 DESC

(2) Select top 1 * from Table order by T1, T2 DESC

These two types of order by (2) have been used in many cases. Previously we thought it was based on the T1 and T2 fields for sorting from large to small. take one entry at work and sort it by two fields. If T1 is equal, use top1. (2) based on T2, but you will find that the problem is not correct. later, I asked why I knew the details of the period. order by is sorted by ASC by default. when t1 and t2 DESC are used, they are actually T1 ASC, T2 DESC, T1 DESC, and T2 DESC. I have never noticed before.

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.