views:

61

answers:

1

I think i am hitting a limit. I have two IN statements in the SQL generated by subsonic. Or am I hitting the varchar ( 8000 ) limit?

When I send i fewer parameters, the statement returns results, when I send in more, the result set comes back blank.

Below is what I am catching in SQL Profiler:

exec sp_executesql N'/* GetDataSet() */ 
 SELECT 
   [dbo].[QuoteDBAll].[quote_id], 
   [dbo].[conn_quote_result].[product_category_name], 
   part_number, 
   quote_result_special_price * ( quote_result_quantity + quote_result_quantity_spare) AS Total, 
   company_name
 FROM [dbo].[QuoteDBAll]
 INNER JOIN [dbo].[conn_quote_result] 
   ON [dbo].[QuoteDBAll].[quote_number] = [dbo].[conn_quote_result].[quote_number]
 INNER JOIN [dbo].[conn_company] 
   ON [dbo].[QuoteDBAll].[company_id] = [dbo].[conn_company].[company_id]
 GROUP BY [dbo].[QuoteDBAll].[quote_id], 
   [dbo].[conn_quote_result].[product_category_name], 
   [dbo].[conn_quote_result].[part_number],
   [dbo].[conn_quote_result].[quote_result_quantity], 
   [dbo].[conn_quote_result].[quote_result_quantity_spare], 
   [dbo].[conn_quote_result].[quote_result_special_price], 
   [dbo].[QuoteDBAll].[quote_status_id], 
   company_name
 HAVING (quote_status_id = @quote_status_id0)
   AND (company_name IN 
     (@in1,@in2,@in3,@in4,@in5,@in6,@in7,@in8,@in9,@in10,
     @in11,@in12,@in13,@in14,@in15,@in16,@in17,@in18,@in19,@in20,
     @in21,@in22,@in23,@in24,@in25,@in26,@in27,@in28,@in29,@in30,@in31))
   AND ([dbo].[conn_quote_result].[product_category_name] IN 
     (@in1,@in2,@in3,@in4,@in5,@in6,@in7,@in8,@in9,@in10,
     @in11,@in12,@in13,@in14,@in15,@in16,@in17,@in18,@in19,@in20,
     @in21,@in22,@in23,@in24,@in25,@in26,@in27,@in28,@in29,@in30,
     @in31,@in32,@in33,@in34,@in35,@in36,@in37,@in38))', 
N'@quote_status_id0 varchar(1),@## varchar(8000),@in1 varchar(15),@in2 varchar(22),
  @in3 varchar(21),@in4 varchar(13),@in5 varchar(5),@in6 varchar(6),@in7 varchar(13),
  @in8 varchar(25),@in9 varchar(8),@in10 varchar(14),@in11 varchar(9),@in12 varchar(11),
  @in13 varchar(16),@in14 varchar(12),@in15 varchar(14),@in16 varchar(16),
  @in17 varchar(11),@in18 varchar(15),@in19 varchar(6),@in20 varchar(12),
  @in21 varchar(12),@in22 varchar(10),@in23 varchar(15),@in24 varchar(15),
  @in25 varchar(15),@in26 varchar(11),@in27 varchar(16),@in28 varchar(20),
  @in29 varchar(6),@in30 varchar(16),@in31 varchar(17),@in32 varchar(11),
  @in33 varchar(18),@in34 varchar(23),@in35 varchar(14),@in36 varchar(19),
  @in37 varchar(12),@in38 varchar(14)', 
@quote_status_id0 = '1', @## = NULL, @in1 = 'Widget1', @in2 = 'Widget2', 
@in3 = 'Widget3', @in4 = 'Widget4', @in5 = 'Widget5', @in6 = 'Widget6', @in7 = 'Widget7', 
@in8 = 'Widget7', @in9 = 'Widget7', @in10 = 'Widget8', @in11 = 'Widget9', @in12 = 'Widget10', 
@in13 = 'Widget11', @in14 = 'Widget12', @in15 = 'Widget13', @in16 = 'Widget14', 
@in17 = 'Widget15', @in18 = 'Widget16', @in19 = 'Widget17', @in20 = 'Widget18', 
@in21 = 'DWidget19', @in22 = 'Widget20', @in23 = 'Widget21', @in24 = 'Widget22', 
@in25 = 'Widget23', @in26 = 'Widget24', @in27 = 'Widget25', @in28 = 'Widget26', 
@in29 = 'Widget27', @in30 = 'Widget28', @in31 = 'Widget29', @in32 = 'Widget30', 
@in33 = 'Widget31', @in34 = 'Widget32', @in35 = 'Widget33', @in36 = 'Widget34', 
@in37 = 'Widget35', @in38 = 'Widget36'
+2  A: 

If you have to ask this question, you should probably use a temp table. Insert your parameters to the temp table and either JOIN your main table to it, or use an IN() predicate against a subquery of the temp table.

In most cases when you have 30+ parameters in an IN() predicate, you're going to find that you need more periodically. Using a temp table allows you to keep increasing the number of values without having to rewrite your query.

And it avoids any possibility of hitting a limit of the number of parameters or a limit on query length.

Bill Karwin
It's also worth considering using a view or sp
Adam