Month: September 2014

Dynamic Pivot Table

DECLARE @DynamicPivotQuery AS NVARCHAR(MAX) DECLARE @ColumnName AS NVARCHAR(MAX) –Get distinct values of the PIVOT Column SELECT @ColumnName= ISNULL(@ColumnName + ‘,’,”) + QUOTENAME(tablecolumn) FROM (SELECT DISTINCT tablecolumn FROM tableName) AS Courses –Prepare the PIVOT query using the dynamic SET @DynamicPivotQuery = N’SELECT Year, ‘ + @ColumnName + ‘ FROM tableName PIVOT(SUM(ColumnName) FOR columnName IN (‘ + @ColumnName + ‘)) AS PVTTable’… Read more →

IEnumerable VS IQueryable

IEnumerable IEnumerable exists in System.Collections Namespace. IEnumerable can move forward only over a collection, it can’t move backward and between the items. IEnumerable is best to query data from in-memory collections like List, Array etc. While query data from database, IEnumerable execute select query on server side, load data in-memory on client side and then filter data. IEnumerable is suitable… Read more →

Difference between document.ready and window.onload or pageLoad

$(document).ready() Best for onetime initialization. Called as soon as DOM is ready; may called slightly before than pageLoad(). Cross browser compatible. Unable to re-attach the functionality to elements/controls of the page affected by partial postbacks. pageLoad() Not best for onetime initialization if used with UpdatePanel. Not Cross browser compatible. Best to re-attach the functionality to elements/controls of the page affected… Read more →

indexer

Indexers Indexers allow instances of a class or struct to be indexed just like arrays. Indexers resemble properties except that their accessors take parameters. class SampleCollection<T> {     // Declare an array to store the data elements.     private T[] arr = new T[100];     // Define the indexer, which will allow client code     // to use [] notation… Read more →

Covariance and Contravariance in Generics

In probability theory and statistics, covariance is a measure of how much two random variables change together. If the greater values of one variable mainly correspond with the greater values of the other variable, and the same holds for the smaller values, i.e., the variables tend to show similar behavior, the covariance is positive.In the opposite case, when the greater… Read more →

Create Reference file for WCF and use manually

Run svcutil.exe serviceurl Generate Service files  codefile.[cs/vb] and output.config config file required to merge with your web.config or app.config. add codefile in your project. add two reference : system.ServiceModel and system.runtime.serialization. now use service.   Read more →

benefits of Razor View

The Razor is the new View engine introduced in MVC 3.0. The View engine is responsible for processing the view files [e.g. .aspx, .cshtml] in order to generate HTML response. The previous versions of MVC were dependent on ASPX view engine.      The syntax for server side code is simplified      The length of code is drastically reduced      Razor syntax is easy to learn… Read more →

REST and Soap

REST stands for Representational State Transfer. This is a protocol for exchanging data over a distributed environment. The main idea behind REST is that we should treat our distributed services as a resource and we should be able to use simple HTTP protocols to perform various operations on that resource. When we talk about the Database as a resource we… Read more →

Get Words from NUMBER

— select dbo.fnNumberToWords(2323422435);   Alter FUNCTION fnNumberToWords(@Number as BIGINT)  RETURNS VARCHAR(1024) AS BEGIN DECLARE @Below20 TABLE (ID int identity(0,1), Word varchar(32)) DECLARE @Below100 TABLE (ID int identity(2,1), Word varchar(32)) INSERT @Below20 (Word) VALUES ( ‘Zero’), (‘One’),( ‘Two’ ), ( ‘Three’), ( ‘Four’ ), ( ‘Five’ ), ( ‘Six’ ), ( ‘Seven’ ), ( ‘Eight’), ( ‘Nine’), ( ‘Ten’), ( ‘Eleven’… Read more →

REST Service

REST stands for Representational State Transfer. This is a protocol for exchanging data over a distributed environment. The main idea behind REST is that we should treat our distributed services as a resource and we should be able to use simple HTTP protocols to perform various operations on that resource. When we talk about the Database as a resource we… Read more →