Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Stored Procedure: Returning Data-No results.Why?

Author  Topic 

Scott Chang
Starting Member

1 Post

Posted - 2007-12-16 : 15:22:06
Hi all,
I copied the following code from the article "Stored Procedure: Returning Data" written by Bill Graziano in this website:
--sp_ReturnData.sql--
USE AdventureWorks
GO
CREATE PROCEDURE dbo.GetPeopleByLastName (@LastName NVARCHAR(5))
AS
SELECT ContactID, FirstName, LastName
FROM Person.Contact
WHERE LastName = @LastName
ORDER By ContactID
GO
EXEC dbo.GetPeopleByLastName @LastName = 'Alexander'
GO
=============================
I executed the above code in my SQL Server Management Studio Express (SSMSE). It ran OK, but I got the following output:
Message: no affected.
Results: just the title "ConttactID", "FirstName", "LastName"
printed and no output of @LastName = 'Alexander' at all.

I am new in doing the Stored Procedure proframming and I do not know where I made a mistake in the sql script. Please help and advise me how to correct this problem and how to get the output printed out.

Thank in advance,
Scott Chang

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2007-12-16 : 15:52:10
Run following in ssmse to see what you get:

SELECT ContactID, FirstName, LastName
FROM Person.Contact
WHERE LastName = 'Alexander'
ORDER By ContactID
Go to Top of Page

graz
Chief SQLTeam Crack Dealer

4149 Posts

Posted - 2007-12-16 : 15:52:25
The @LastName parameter needs to be NVARCHAR(50). It's truncating the 'Alexander' down to 'Alexa'.



=================================================
Creating tomorrow's legacy systems today. One crisis at a time.
Go to Top of Page
   

- Advertisement -