Wednesday, March 31, 2010

Find the any number(sec, third ,sec last) Top Row or bottom row using sql.

This Example for find 4th row

SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY MytblCOlumn_ID) AS RowNumber FROM tbl_Murli) as tbl_Murli WHERE RowNumber = 4
Calculate the execution time of query

DECLARE @start datetime
SELECT @start = getdate()
BEGIN TRANSACTION
-- Stuff to test comes here.
--Select * from tbltest
Declare @int int
Set @int = 0
Print @start
While(@int < 200000)
Begin
Print @int;
Set @int = @int +1
End
--PRINT 'It took ' + ltrim(str(datediff(ss, @start, getdate()))) + ' sec.'
Select Ltrim(STR(DATEDIFF(SS,@Start,Getdate())))+ ' Sec'
ROLLBACK TRANSACTION