Thursday, 25 February 2016

Sql server table columns with comma separated string using COALESCE


//Sql Query

DECLARE @ColStr VARCHAR(MAX)
SELECT @ColStr = COALESCE(''+@ColStr +',' ,'') +'['+ name+']' FROM sys.columns where object_name(object_id)='TableName'

Print @ColStr


// Result

 [Active],[StateCode],[StateName]

Friday, 19 February 2016

Create a field primary key to access database using c#

// Create with Single Filed

CREATE UNIQUE INDEX myNewIndex ON test (ID) WITH PRIMARY

// Create with Multiple Filed

CREATE UNIQUE INDEX myNewIndex ON test (ID,uname,ut) WITH PRIMARY





// Drop key index

Drop INDEX myNewIndex ON test

Wednesday, 3 February 2016

Divide by zero error encountered in sql




--// Details

SELECT COALESCE(SUM(isnull(ColumnName,0)) / NULLIF(SUM(isnull(ColumnName,0)),0), 0)

--// Function

SELECT COALESCE(SUM(isnull(0,0)) / NULLIF(SUM(isnull(0,0)),0), 0)

--// Result

0.000000

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...