Thứ Sáu, ngày 12 tháng 8 năm 2016

Calculating a selector's specificity

A selector's specificity is calculated as follows:
  • count the number of ID selectors in the selector (= a)
  • count the number of class selectors, attributes selectors, and pseudo-classes in the selector (= b)
  • count the number of type selectors and pseudo-elements in the selector (= c)
  • ignore the universal selector
Selectors inside the negation pseudo-class are counted like any other, but the negation itself does not count as a pseudo-class.
Concatenating the three numbers a-b-c (in a number system with a large base) gives the specificity.
Examples:
*               /* a=0 b=0 c=0 -> specificity =   0 */
LI              /* a=0 b=0 c=1 -> specificity =   1 */
UL LI           /* a=0 b=0 c=2 -> specificity =   2 */
UL OL+LI        /* a=0 b=0 c=3 -> specificity =   3 */
H1 + *[REL=up]  /* a=0 b=1 c=1 -> specificity =  11 */
UL OL LI.red    /* a=0 b=1 c=3 -> specificity =  13 */
LI.red.level    /* a=0 b=2 c=1 -> specificity =  21 */
#x34y           /* a=1 b=0 c=0 -> specificity = 100 */
#s12:not(FOO)   /* a=1 b=0 c=1 -> specificity = 101 */
Note: Repeated occurrances of the same simple selector are allowed and do increase specificity.
Note: the specificity of the styles specified in an HTML style attribute is described in CSS 2.1. [CSS21].

Thứ Sáu, ngày 01 tháng 4 năm 2016

Sử dụng Cursor trong SQL Server

DECLARE @tblStudent table(Name varchar(50), Age int);
insert into @tblStudent(Name,Age) values('Name 1',1)
insert into @tblStudent(Name,Age) values('Name 2',2)

DECLARE @name VARCHAR(50) 
DECLARE @age int

DECLARE myCursor CURSOR FOR  
SELECT Name, Age
FROM @tblStudent

OPEN myCursor   
FETCH NEXT FROM myCursor INTO @name,@age  

WHILE @@FETCH_STATUS = 0   
BEGIN   
       print(@name + ' - ' + cast(@age as varchar))
       FETCH NEXT FROM myCursor INTO @name ,@age 
END   

CLOSE myCursor   
DEALLOCATE myCursor

Phân trang trong MS SQL Server 2012

declare @currPage int = 2,-- trang hiện tại
@recodperpage int = 20;-- số dòng trên 1 trang

select *,COUNT(*) OVER () as TotalRecords from [TenBang]
order by [TenCot]
OFFSET (@currPage - 1)*@recodperpage ROWS
FETCH NEXT @recodperpage ROWS ONLY

Phân trang theo cách truyền thống sử dụng ROW_NUMBER()