Wrox Programmer Forums
|
SQL Server 2005 General discussion of SQL Server *2005* version only.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2005 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 4th, 2008, 05:17 PM
Registered User
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default SQL In book not working

I'm working my way through Beginning SQL Server 2005 Administration and I'm in Chapter 8, page 306. The exercise includes creating a stored proc for inserting a credit card that will cause an error to be raised. The code is:
CREATE PROCEDURE AddNewCreditCard
@CardType nvarchar(50),
@CardNumber nvarchar(25),
@ExpMonth tinyint,
@ExpYear smallint
AS
DECLARE @username varchar(60)
DECLARE @loginame varchar(60)
DECLARE @CreditCardInfo Table(CreditCardID INT)
DECLARE @CreditCardID INT
SET @loginame = suser_sname()
SET @username = user_name()

I keep getting the following error:
Msg 8152, Level 16, State 2, Procedure RecordDDL, Line 8
String or binary data would be truncated.
The statement has been terminated.

Everything looks good. The sizes for card type and number match the table and creditcardinfo is INT.

Why is the code getting an error? I feel silly asking this, but that's life.

B
 
Old August 4th, 2008, 06:19 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Ummm...look at the error message.

It says the error is in
    Procedure RecordDDL

Doesn't say anything about the SP you are showing.
 
Old August 5th, 2008, 12:36 PM
Registered User
 
Join Date: Aug 2008
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks. I was blanking out on the error message. The stored Proc worked when I deleted the trigger RecordDDL. Not sure why it was failing when it worked in Chapter 5, but stuff happens. Thank you for your help.

 
Old August 5th, 2008, 12:54 PM
Friend of Wrox
 
Join Date: Jun 2008
Posts: 1,649
Thanks: 3
Thanked 141 Times in 140 Posts
Default

Well, the error message is pretty clear: The SP is trying to shove data into some DB field or even some procedure variable that is longer than the field/variable.

Most often, this happens with VARCHAR/NVARCHAR fields. You declare one to hold, say, 30 characters (e.g., VARCHAR(30)) and then your code (or the data you are handling) tries to put 31 or more characters into that field/variable. Kablooey.

Chances are, if you can figure out WHAT field or variable is too short, just increasing its size will fix all. And the code may have accidentally worked for the author of the book because the data he tested with was shorter than your data. (Which just shows that even the code in books could stand to go through a QA process.)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Working with the book on two machines... Bruce.Wiki BOOK: Beginning ASP.NET 3.5 : in C# and VB BOOK ISBN: 978-0-470-18759-3 5 October 30th, 2008 11:53 AM
Code in Book Not Working kaaveryups SQL Server 2005 2 April 11th, 2007 01:29 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.