17.06.2013 Views

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

Beginning Microsoft SQL Server 2008 ... - S3 Tech Training

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Go ahead and run this once:<br />

DECLARE @Return int;<br />

EXEC @Return = HumanResources.uspEmployeeHireInfo2<br />

@BusinessEntityID = 1,<br />

@JobTitle = ‘His New Title’,<br />

@HireDate = ‘1996-07-01’,<br />

@RateChangeDate = ‘<strong>2008</strong>-07-31’,<br />

@Rate = 15,<br />

@PayFrequency = 1,<br />

@CurrentFlag = 1;<br />

SELECT @Return;<br />

And everything seems to run fine, but execute it a second time and we get some different results:<br />

Duplicate Rate Change Found<br />

-----------<br />

-2000<br />

(1 row(s) affected)<br />

We tried to insert a second row with the same pay history, but <strong>SQL</strong> <strong>Server</strong> wouldn’t allow that. We’ve<br />

used PRINT to supply informative output in case the statement is being executed without the Query<br />

window, and we’re outputting a specific return value that the client can match against a value in a<br />

resource list.<br />

Now, let’s try the same basic test, but use an invalid BusinessEntityID:<br />

DECLARE @Return int;<br />

EXEC @Return = HumanResources.uspEmployeeHireInfo2<br />

@BusinessEntityID = 99999,<br />

@JobTitle = ‘My Invalid Employee’,;<br />

@HireDate = '<strong>2008</strong>-07-31',<br />

@RateChangeDate = ‘<strong>2008</strong>-07-31’,<br />

@Rate = 15,<br />

@PayFrequency = 1,<br />

@CurrentFlag = 1;<br />

SELECT @Return;<br />

We get a similar error message and return code, but each is slightly different to allow for the specific<br />

error detected:<br />

BusinessEntityID Not Found<br />

-----------<br />

-1000<br />

(1 row(s) affected)<br />

Chapter 12: Stored Procedures<br />

389

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!