SQL tips

 How to Avoid cursors:

http://www.code-magazine.com/Article.aspx?quickid=060113

USE AdventureWorks
GO
DECLARE @TransactionID int
, @TransactionType nchar(1)
, @Quantity int

SET @TransactionID = (SELECT MIN(TransactionID)¼br> FROM Production.TransactionHistory)
WHILE @TransactionID IS NOT NULL
BEGIN
SET @TransactionID = (SELECT MIN(TransactionID)¼br> FROM Production.TransactionHistory WHERE TransactionID > @TransactionID)
END

UPDATE FROM syntax : From one table to another..

http://sqlblog.com/blogs/hugo_kornelis/archive/2008/03/10/lets-deprecate-update-from.aspx

Posted by admin on Jun 25 2009 in SQLServer

SQL Toolset

strSQL is my custom developed Code Generator : Download it for free 

strsQL http://www.sim1.com.au/home.aspx?MID=7

===========================================================

Other Tools

DBAMgr2k http://www.asql.biz/en/ 

http://www.asql.biz/en/Download.aspx#DbaMgr2K

Posted by admin on Jun 15 2009 in SQLServer Tags: , , , ,

Raise Errors in SQL stored procedures…

Here is an reference to Raise an error in the stored procedure so that it can be caught in the calling application.

BEGIN TRAN

 UPDATE RequestStatus
 SET
           StatusName = @StatusName,
           Description = @Description,
           Color = @Color,
           Status = @Status,
           DateUpdated = getdate(),
           UpdatedBy = @UpdatedBy
 WHERE
           StatusID = @StatusID
    IF (@@error!=0)
 BEGIN
  RAISERROR  21001 ‘lp_UpdateRequestStatus: Cannot update  in RequestStatusDetails ‘
  ROLLBACK TRAN
  RETURN(1)
 END

COMMIT TRAN

 RETURN(0)Â

Posted by admin on Mar 23 2009 in SQLServer