Solved

calling a stored procedure with argument

Posted on 2012-04-05
5
354 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 100 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 39

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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now