SQL Server statistical reports (continuously added to favorites)

Source: Internet
Author: User
Create Table # T (out_no varchar (10) primary key, date datetime, part varchar (30), qty numeric (12, 4), price numeric (12, 4 )) insert into # tselect 'a01', '2017-1-11 ', 'b001', 2009, 100 Union allselect 'a02', '2017-1-12 ', 'b002', 1.1, 1.3 Union allselect 'a03', '2014-2-22 ', 'b003', 2009, 120 Union allselect 'a04 ', '2014-3-22', 'b004 ', 1.5, 1.2 Union allselect 'a05 ', '2014-4-20', 'b005 ', 2009, 600 Union allselect 'a06', '2014-4-22', 'b006 ', 1.6, 1.6 ---- select * from # tselect month = 'shipment qty ', [January] = sum (case when month (date) = 1 then qty else 0 end ), [February] = sum (case when month (date) = 2 then qty else 0 end), [March] = sum (case when month (date) = 3 then qty else 0 end), [April] = sum (case when month (date) = 4 then qty else 0 end ), [May] = sum (case when month (date) = 5 then qty else 0 end) from # tunion allselect month = 'shipping amount ', [January] = sum (case when month (date) = 1 then price * qty else 0 end), [February] = sum (case when month (date) = 2 then price * qty else 0 end), [March] = sum (case when month (date) = 3 then price * qty else 0 end ), [April] = sum (case when month (date) = 4 then price * qty else 0 end), [May] = sum (case when month (date) = 5 then price * qty else 0 end) from # T/* month, month) */drop table # T

2,

Assume that the field name is name and its values are separated by commas.

The value is 111,111 xu2, 1112 '.

Now, we need to write a statement to search for the name value like '11.

It is reasonable to say that there is no 11 in this name, and the result we want is to return null.

However, if we select * from student where name like '% 100', we can still query the results normally.

---

At this point, we should use the following statement to implement:

 

Select * from student where name like '% 100' -- according to my idea, it cannot be found. But the result is:
-- Solution: add the number before and after the SQL field name, and add the number before and after the Compare value.
-- Note that when the field name is added with a comma, it must be connected in the form of a string, and cannot be directly ', name ,'
Select * from student where ',' + name + ', 'like' %, 111, %'
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.