Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

calling a stored procedure with argument

Posted on 2012-04-05
5
Medium Priority
?
365 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 40

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

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

722 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