SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 parameter query int error
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

shanmugaraj
Posting Yak Master

212 Posts

Posted - 04/23/2013 :  07:51:10  Show Profile  Send shanmugaraj a Yahoo! Message  Reply with Quote
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
Flowing Fount of Yak Knowledge

India
2169 Posts

Posted - 04/23/2013 :  08:06:29  Show Profile  Reply with Quote
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
Flowing Fount of Yak Knowledge

3326 Posts

Posted - 04/23/2013 :  08:38:19  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000