Question : I need to send a comma delimited string to a stored procedure to run an in(@parameter) query

I am running a report from reporting services using a sp (i have attached the code for the sp in the code section) i n reporting services there is a parameter of availible vendors in a multiple select drop down box which sends data to the @vid1 param. The @vid1 param is used in a in statement see the code. The @category is the same scenario. I have never done this with a stored procedure before using an in statement does not seem to work. I keep getting the following error conversion failed when converting the varchar value '363,390' to data type int. How do i change the attached code to work with a comma delimited string in a parameter to be used within a in statement.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
ALTER proc [dbo].[h_reporttotalqtyindatereange]
	@vid1 varchar(8000),
	@date1 varchar(20),
	@date2 varchar(20),
	@category varchar(8000)
as 
 
declare @vid varchar(8000)
select @vid=@vid1
SELECT DISTINCT 
                      dbo.getvendornamewithoutrules(h_items.item_id) AS vendor, dbo.lowestcostinlistofvendors(h_items.item_id, @vid) AS lowprice, 
                      h_po_detail.po_detail_item, SUM(CAST(h_po_detail.po_detail_quantity AS numeric) * CAST(h_items_cost.items_cost_price AS money)) AS amount, 
                      SUM(CAST(h_po_detail.po_detail_quantity AS numeric)) AS Qty, h_items.item_name, h_items.item_category, h_categories.categories_name
FROM         h_po_detail INNER JOIN
                      h_items ON h_po_detail.po_detail_item = h_items.item_id INNER JOIN
                      h_categories ON h_items.item_category = h_categories.categories_id INNER JOIN
                      h_vendors ON h_po_detail.po_detail_vendor = h_vendors.vendor_id LEFT OUTER JOIN
                      h_items_cost ON h_po_detail.po_detail_uom = h_items_cost.items_cost_id
WHERE     (h_items.item_category IN (@category)) AND (h_po_detail.po_detail_create_date BETWEEN @date1 AND @date2)
GROUP BY dbo.getvendornamewithoutrules(h_items.item_id), dbo.lowestcost(h_items.item_id), h_po_detail.po_detail_item, h_items.item_name, 
                      h_items.item_category, h_categories.categories_name, h_items.item_id
ORDER BY Qty DESC
Open in New Window Select All

Answer : I need to send a comma delimited string to a stored procedure to run an in(@parameter) query

The suggestion is to check and see what exactly you want to extract and to make sure that your select statements are doing that. I already pointed you that the function is using the @cost1 whithout any affect on the output so the problem resides in the logic you are using. I don't know aht are you after and what data you have, this should be for you to figure out.

However the technique for the comma separated values that I gave you works and I implemented it correctly to the code I was given. It is your task to correct the code.
Random Solutions  
 
programming4us programming4us