Conditional sorting and paging in T-SQL

DECLARE
@Take INT,
@Skip INT,
@SortField VARCHAR(100)

;WITH workers AS (
SELECT 
	   w.WorkerId,
	   w.FirstName,
	   w.LastName,
	   w.Specialization,    
	   ROW_NUMBER() OVER 
	   (
		  ORDER BY 			 
			 CASE WHEN @SortField = 'WorkerId#desc' THEN w.WorkerId
			 END DESC,
			 CASE WHEN @SortField = 'WorkerId#asc' THEN w.WorkerId
			 END ASC,
			 CASE WHEN @SortField = 'LastName#desc' THEN w.LastName
			 END DESC,
			 CASE WHEN @SortField = 'LastName#asc' THEN w.LastName
			 END ASC,
			 CASE WHEN @SortField = 'Specialization#desc' THEN w.Specialization
			 END DESC,
			 CASE WHEN @SortField = 'Specialization#asc' THEN w.Specialization
			 END ASC,				 
			 CASE WHEN 1 = 1 THEN w.LastName
			 END ASC
	   ) AS rowNumber
    FROM Workers w
)

    SELECT 
	   w.WorkerId,
	   w.FirstName,
	   w.LastName
	   w.Specialization,
	   (SELECT COUNT(*) FROM workers) AS TotalRows
    FROM workers w
    WHERE rowNumber BETWEEN @Skip + 1 AND @Skip + @Take
    ORDER BY rowNumber ASC

Advertisements

SVG vs. Canvas

SVG (Scalable Vector Graphics) Canvas
zbiór elementów DOM jeden element w zbiorze DOM
mało wydajne renderowanie skomplikowanych grafik przeznaczone do renderowania skomplikowanych grafik
tworzenie grafik w oparciu o XML grafiki tworzone w języku JavaScript