Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 parameter query int error

Author  Topic 

shanmugaraj
Posting Yak Master

219 Posts

Posted - 2013-04-23 : 07:51:10
Error :
Conversion failed when converting the varchar value 'SELECT * from category WHERE category.category_id IN ( ' to data type int.



Query :


CREATE PROCEDURE [dbo].[usp_get_data]
( @plan_id int, @category_id int
)
AS
set @sql_query = 'SELECT * from category WHERE category.category_id IN ( '+ @category_id +') and [plan].plan_id in ( '+ @plan_id +')'
exec (@sql_query )


THANKS
SHANMUGARAJ
nshanmugaraj@gmail.com

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-04-23 : 08:06:29
Here @plan_id, @category_id are integer types.. then what is the purpose of IN clauses ?

CREATE PROCEDURE [dbo].[usp_get_data]
( @plan_id int, @category_id int
)
AS
SELECT * from category WHERE category.category_id = @category_id and [plan].plan_id =@plan_id

The above is enough for checking conditions based on input params...

If you want your procedure only means you need to cast @plan_id, @category_id variables to VARCHAR

--
Chandu
Go to Top of Page

James K
Master Smack Fu Yak Hacker

3873 Posts

Posted - 2013-04-23 : 08:38:19
To add to what Chandu suggested,something does not seem quite right with the SELECT query itself. You are referring to plan_id from plan table, yet plan table is not listed in the from clause. Is plan_id a column in category table? If so,
SELECT * from category 
WHERE category.category_id = @category_id and category.plan_id =@plan_id
Go to Top of Page
   

- Advertisement -