Monday, 31 March 2014

Find Length of string with LEN function in sql server

It returns the number of characters of string expression but with excluding trailing blanks.

SELECT LEN('Sql Server Database')

-- Result : 19


Tuesday, 25 March 2014

Find Age from Date of Birth in Sql Server


declare @dob datetime = '1952-08-14 21:11:19.300'

select CAST( DATEDIFF(Y , @dob , getdate() )/365.25 as int)

-- 365 are the Number of Average days in 4 years


Sunday, 23 March 2014

Select Top N rows from a table in Sql Server

Suppose if N=10 then ,

Select Top 10 * from Person

IF you want to Select only particular columns then,

Select Top 10 Name , City , Age from Person




Get current system date in Sql Server

SELECT GETDATE()

-- Result : 2014-03-23 19:57:21.630


Wednesday, 12 March 2014

Find Version of Sql Server through query

select @@Version

Result from My Computer:

--Microsoft SQL Server 2012 - 11.0.2100.60 (X64)
--Feb 10 2012 19:39:15
--Copyright (c) Microsoft Corporation
--Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )


Wednesday, 5 March 2014

#region in Visual Studio

It allows block of code to expand or collapse when using the outlining feature of the Visual Studio Code Editor. You can write namespaces, classes, methods, interfaces, delegates, events inside it.

#region MyRegion

//  Namespaces
//  Classes
//  Methods
//  Interfaces
//  Delegates
//  Events

#endregion


Page Pre_Render Event in Asp.net C#

If you want to perform some action after the page is completely loaded and Ready to Render then the desired code should be written in this event.

protected void Page_PreRender(object sender, EventArgs e)
{
    // Your Code Goes Here
}