29 September, 2011

Ranking function of MsSQL Server 2005

All ranking function of SQL Server 2005:-

ROW_NUMBER () OVER ([] )
Returns the sequential number of a row within a partition of a result set, starting at 1 for the first row in each partition.


RANK () OVER ([] )
Returns the rank of each row within the partition of a result set.


DENSE_RANK () OVER ([] )
Returns the rank of rows within the partition of a result set, without any gaps in the ranking.


NTILE (integer_expression) OVER ([] )
Distributes the rows in an ordered partition into a specified number of groups.



11 September, 2011

Add link server in MsSQL 2008/2005

EXEC master.dbo.sp_addlinkedserver
@server = N'GXBDDA-S3013', @provider = 'SQLOLEDB'
, @datasrc = N'Gxbdda-S3013', @srvproduct=''

EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname=N'Gxbdda-S3013',@useself=N'False',@locallogin=NULL
,@rmtuser='ADM_SMART',@rmtpassword='smartsmart'

exec sp_serveroption @server='Gxbdda-S3013', @optname='rpc', @optvalue='TRUE'
exec sp_serveroption @server='Gxbdda-S3013', @optname='rpc out', @optvalue='TRUE'