Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

calling a stored procedure with argument

Posted on 2012-04-05
5
Medium Priority
?
368 Views
Last Modified: 2012-08-14
hello,

I'm calling my stored procedure and the fact having the first field as an incremental value is causing me trouble.

first field is an INT and setup as IDENTITY. However, in the stored procedure I must specify it and I"m not passing any values to it but then I get an error message as Error converting data type varchar to int.  since my 2nd field being passed to SP is varchar. What is the right approach here?

here is the code:

CREATE PROCEDURE 
add_node (
			@p0 int, 
			@p1  varchar(35), 
			@p2  int, 
			@p3  int, 
			@p4  bit, 
			@p5  varchar(100) 
) as

insert into test(category_Id, name, lft, rgt, visible, description)
values(@p0, @p1, @p2, @p3, @p4, @p5)
go
add_node 'test', 200, 300, 0 ,'some info here ...'   
go
select * from test 

Open in new window


Thanks!
0
Comment
Question by:akohan
5 Comments
 
LVL 5

Expert Comment

by:truinx
ID: 37813760
You are passing string in line 14. 'Test' for @p0 which is int?
0
 
LVL 6

Accepted Solution

by:
yawkey13 earned 400 total points
ID: 37813787
Why must you pass the ID at all?  If it is an identity, it should auto increment.

Eliminate the @p0 param in the sproc def and change your insert statement to:

insert into test(name, lft, rgt, visible, description)
values(@p1, @p2, @p3, @p4, @p5)
0
 
LVL 41

Expert Comment

by:Kyle Abrahams
ID: 37813860
yawkey is correct.

Then you return the id to your program via:

select scope_identity()
0
 

Author Comment

by:akohan
ID: 37814517
Thanks. I did that yet I'm not sure why I am getting

Invalid object name 'dbo.test'
0
 

Author Comment

by:akohan
ID: 37814561
please ignore my last question. found the issue.
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
When trying to connect from SSMS v17.x to a SQL Server Integration Services 2016 instance or previous version, you get the error “Connecting to the Integration Services service on the computer failed with the following error: 'The specified service …
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question