Friday, 3 June 2011

Replicate Function in Sql


*    This is T-SQL Function and it repeats the string/character expression 
N number of times specified in the function.
 
//LIMS Database
IF EXISTS(SELECT name FROM sys.tables WHERE name = 't1')
   DROP TABLE t1;
GO
CREATE TABLE t1 
(
 c1 varchar(3),
 c2 char(3)
);
GO
INSERT INTO t1 VALUES ('2', '2');
INSERT INTO t1 VALUES ('37', '37');
INSERT INTO t1 VALUES ('597', '597');
GO
SELECT REPLICATE('0', 3 - DATALENGTH(c1)) + c1 AS 'Varchar Column',
       REPLICATE('0', 3 - DATALENGTH(c2)) + c2 AS 'Char Column'
FROM t1;
GO


Server Side Paging in SQL Server 2011 –Denali


--Create By : Nilay Mistry
--Date         : 02-Jun-2011

DECLARE @RowsPerPage INT = 10,
DECLARE @PageNumber INT = 5

SELECT *
FROM EmployeeMaster
ORDER BY EmployeeID
OFFSET
@PageNumber*@RowsPerPage ROWS
FETCH NEXT 10 ROWS ONLY
GO

Monday, 30 May 2011

Difference Between SELECT * vs SELECT COUNT(*)

* Difference Between SELECT * vs SELECT COUNT(*) ???


Select * - resulting Error
Select * - resulting Error
Select count * - NOT resulting Error
Select count * - NOT resulting Error



“Select *” will return all columns from a table (or a result set), if no table specified, error happens.

“Select count(*)” will return the number of a table (or result set), if no table specified, it will scan an internal table of constants which has 1 row

Friday, 20 May 2011

Import csv file and return Table in Sql

Import csv file and return Table :

CREATE TABLE Test
(ID INT,FirstName VARCHAR(40),LastName VARCHAR(40),BirthDate SMALLDATETIME)GO


BULK
INSERT
TestFROM 'c:\Nilay.txt'WITH(FIELDTERMINATOR = ',',ROWTERMINATOR = '\n')GO--Check the content of the table.SELECT *FROM Test
GO

Thursday, 19 May 2011

T-SQL Query

Recently Executed T-SQL Query :

SELECT deqs.last_execution_time 
 AS [Time], dest.TEXT AS [Query]
 FROM sys.dm_exec_query_stats
AS deqsCROSS APPLY sys.dm_exec_sql_text(deqs.sql_handle) AS dest 
ORDER BY deqs.last_execution_time DESC

Keyboard ShortCut Visual Studio 2010

Improve Your Efficiency with Visual Studio 2010 Shortcut :

LOVE AND FEEL THE DEVELOPMENT...