Friday, January 29, 2010

Thursday, January 28, 2010

Thursday, January 14, 2010

Custom Error in Sql Server 2008

declare @un tinyint
declare @UserName Varchar(200) = 'abc'
declare @RoleID int = 3
select @un = COUNT(*) from LoginDetails where UserName = @UserName and RoleID = @RoleID
if @un > 0
begin
declare @ErrorMessage1 nvarchar(max), @ErrSeverity1 int
set @ErrorMessage1 = 'UserName Already Exists. Try different User Name'
set @ErrSeverity1 = 16
RAISERROR(@ErrorMessage1, @ErrSeverity1, 1)
end

Delete Duplicate records from a table in sql

DECLARE @Duplicate TABLE (ID INT,FNAME VARCHAR(10),MNAME VARCHAR(10))
INSERT INTO @Duplicate VALUES(1, ‘AAA’,'CCC’)

INSERT INTO @Duplicate VALUES(2, ‘BBB’,'DDD’)

INSERT INTO @Duplicate VALUES(1, ‘AAA’,'CCC’)

INSERT INTO @Duplicate VALUES(2, ‘BBB’,'DDD’)

INSERT INTO @Duplicate VALUES(1, ‘AAA’,'CCC’)

INSERT INTO @Duplicate VALUES(2, ‘BBB’,'DDD’)

INSERT INTO @Duplicate VALUES(3, ‘BCB’,'DGD’)

WITH CTE as(SELECT ROW_NUMBER() OVER(PARTITION BY ID, FName, MName ORDER BY (SELECT 1)) AS RowID,*FROM @Duplicate)

SELECT ID, FName, MNameFROM CTEWHERE RowID = 1

ref: http://blog.sqlauthority.com/2007/03/01/sql-server-delete-duplicate-records-rows/

http://www.databasejournal.com/features/mssql/article.php/3572301/RowNumber-function-in-SQL-Server-2005.htm

autocomplete with jquery

http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/