日期:2014-05-16  浏览次数:20443 次

winform调用存储过程失败,怎么回事?
写了个存储过程:
USE [BStyle_Bus]
GO
/****** Object:  StoredProcedure [dbo].[usp_InventoryAnalysis]    Script Date: 03/17/2014 09:14:35 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER procedure [dbo].[usp_InventoryAnalysis]
@selectedDate varchar(max)=null,--时间选择
@customerCodes varchar(max)=null,--客户代码
@warehourseCodes varchar(max)=null,--仓库代码
@goodsCodes varchar(max)=null,--商品代码
@isShowColor int=0,--显示颜色,默认未选择
@isShowSize int=0,--显示尺寸,默认未选择
@isShowNegative int=0,--只显示负库存,默认未选择
@isShowNotZero int=1,--不包含库存为零,默认选择
@completed INT OUTPUT 
as 
declare
 @sql varchar(max),
 @SqlWhr VARCHAR(MAX) = '',
 @SqlHaving VARCHAR(MAX) = '',
 @GG_Select VARCHAR(MAX) = '',
 @GG_Inner VARCHAR(MAX) = '',
 @GG_Group VARCHAR(MAX) = ''
 
SET @completed=0; 
set @SqlWhr= @SqlWhr + ' and CustomerCode in('+@customerCodes+')';  
if  @warehourseCodes is not null
begin
set @SqlWhr= @SqlWhr + ' and WareHourseCode in('+@warehourseCodes+')'; end

if @goodsCodes is not null
begin
set @SqlWhr= @SqlWhr + ' and GoodsCode in('+@goodsCodes+')'; end

if @selectedDate is not null

begin
set  @SqlWhr= @SqlWhr +' and CreateDate<='+@selectedDate;  
end

if @isShowColor=1
begin
set @GG_Select=@GG_Select + 'ColorCode,Color,'; 
set @GG_Group=@GG_Group+'ColorCode,Color,'
end

if @isShowSize=1
begin
set @GG_Select=@GG_Select + 'SizeCode,Size'; 
set @GG_Group=@GG_Group+'SizeCode,Size'
end

if @isShowNotZero=1
set @SqlHaving=@SqlHaving+' and SUM(Count)<>0';

if @isShowNegative=1
set @SqlHaving=@SqlHaving+' and SUM(Count)<0';

set @sql='
select CustomerCode,CustomerName,WareHourseCode,WareHourse,GoodsCode,GoodsName,AreaName,BigClass,Serie,Season,[Year],Wave,ColorSystem,Brand,'+@GG_Select+',SmallClass,Moduel,SelectionOfPricing,SelectionOfMoney,SUM(Count) Count
from GoodsStockAnalysis 
where 1=1 '+@SqlWhr+
' Group by CustomerCode,CustomerName,WareHourseCode,WareHourse,GoodsCode,GoodsName,AreaName,BigClass,Serie,Season,[Year],Wave,ColorSystem,Brand,'+@GG_Group+',SmallClass,Moduel,SelectionOfPricing,SelectionOfMoney
Having 1=1 '+@SqlHaving
print(@sql)
exec(@sql)
SET @completed = 1;                 
Ret:        
RETURN         
Err:          
SELECT @completed AS RESULT        
RETURN 

然后我winform中使用的时候,显示在',' 附近有语法错误。
winform调用的代码
   findedCustomer = new List<string>();
            findedWarehouse = new&nbs