Skip to main content

Posts

Showing posts from September, 2010

Difference between DataSet and DataReader

Data Reader i) Data Reader is readonly so we can't do any transaction on them. ii) Data Reader will be the best choice where we need to show the data to the user which requires no transaction. iii) Data Reader is like a forward only recordset. It fetches one row at a time so very less network cost compare to DataSet(Fethces all the rows at a time). As DataReader is forward only so we can't fetch data randomly. iv) .NET Data Providers optimizes the datareader to handle huge amount of data. DataSet i) DataSet is an in memory representation of a collection of Database objects including tables of a relational database schemas. ii) DataSet is always a bulky object that requires a lot of memory space compare to DataReader. iii) DataSet fetches all data from the datasource at a time to its memory area. So we can traverse through the object to get the required data like querying database. iv) DataSet can have relationship between the fetched tables. If you feel this tips help you th

Select N th Maximum - SQL Server 2005

To Select Nth Maximum Value using TOP key word, You can try the following Stored Procedure. CREATE PROCEDURE SP_SelectTopN (@N INT ) /****************************************/ /* Created By : Loganathan V */ /* Created On: 21-Sep-2010, Tuesday */ /* Purpose : To Get the N th Top Value from*/ /*                Recordset. */ /* How to : EXEC SP_SelectTopN */ /*             : EXEC SP_SelectTopN 4 */ /****************************************/ AS BEGIN         DECLARE @P INT         SELECT @P=@N         SELECT TOP 1 * FROM         ( SELECT TOP (@P) * FROM SALARYTABLE ORDER BY SALARY DESC )   AS  TOPNRECORDS ORDER BY SALARY ASC END To Run the Stored Procedure follow this:   EXEC SP_SelectTopN 4   To Select Nth Maximum Value without the use of TOP key word, You can try the following Stored Procedure. CREATE PROCEDURE USP_SELECT_TOP_NTH (@N INT = NULL ) AS /****************************************/ /* Created By : Loganathan V */ /* Created On: 21-Sep-2010, Tuesday */ /* Purpose

Multiplication Table in SQL Server

Multiplication Table in SQL Server This query gives the multiplication table from 1 to 10. DECLARE @A INT,                   @B INT,                   @C INT,                   @D VARCHAR (100)                   SELECT @A=1                  PRINT ' MULTIPLICATION TABLE 1-10' /****************************************/ /* Created By : Loganathan V */ /* Created On: 20-Sep-2010, Monday */ /* Purpose : Multiplication Table */ /* How to : RUN THE QUERY */ /****************************************/ WHILE (@A<=10) BEGIN            SELECT @B=1             SELECT @D=''            WHILE (@B<=10)              BEGIN               SELECT @C=1                SELECT @C=@A*@B               SELECT @D=+@D+ CAST (@C AS VARCHAR )+' '               SELECT @B=@B+1              END             PRINT @D+ CHAR (9)             SELECT @A=@A+1 END The output of this query will be like this. MULTIPLICATION TABLE 1-10  1    2   3   4  5   6   7  8   9   10  2    4   6