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 January 2nd, 2008, 01:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default PRINT statement

Hello,

I wrote a stored procedure to experiment with returning an identity value to some ADO.NET code. The procedure and the code work fine. Here's is the procedure:
Code:
CREATE PROCEDURE procIdentityInsert

    @ID int OUTPUT,
    @CategoryName varchar(50)
)
AS
    INSERT INTO identitytable
    (CategoryName) 
    VALUES 
    (@CategoryName)
    SET  @ID = SCOPE_IDENTITY()
How can I use the PRINT staement in SQL Express 2005 to test this procedure? I tried:
Code:
DECLARE @ID int
EXEC procIdentityInsert @ID OUTPUT, 'Category 5'
PRINT 'ID: ' + @ID
the insert works, but I get the error:

(1 row(s) affected)
Msg 245, Level 16, State 1, Line 3
Conversion failed when converting the varchar value 'ID: ' to data type int.

Do I have to convet the int to s atring or something?

Thanks,

Bob

 
Old January 2nd, 2008, 05:40 AM
Friend of Wrox
 
Join Date: Sep 2005
Posts: 812
Thanks: 1
Thanked 53 Times in 49 Posts
Default

You are trying to concatenate a string with integer

try the following

Print 'ID = ' + cast(@ID as varchar)

instead of

PRINT 'ID: ' + @ID

Cheers
Shasur



http://www.dotnetdud.blogspot.com

VBA Tips & Tricks (http://www.vbadud.blogspot.com)
 
Old January 2nd, 2008, 07:24 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,093
Thanks: 1
Thanked 12 Times in 11 Posts
Default

Mush better.

Code:
DECLARE @ID int
EXEC procIdentityInsert @ID OUTPUT, 'Category 8'
Print 'ID = ' + cast(@ID as varchar)
yields:

Code:
(1 row(s) affected)
ID = 8
Thanks much.

Bob








Similar Threads
Thread Thread Starter Forum Replies Last Post
Textbox problem print preview vs. print jenisageek Access 5 May 2nd, 2008 12:54 PM
print the hidden page without the print dialog box kayzem Classic ASP Basics 0 April 21st, 2005 11:31 PM
Print and print preview file on the website withou appleLover General .NET 0 February 19th, 2005 02:24 AM
Macro to print to different print objects mikericc Access 1 April 21st, 2004 10:57 AM





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