我想在狐表里调用存储过程 jd_hd,带四个参数tm,hd,sta,ends。其中后两个是日期格式
都是引用的窗口控件的值。
Dim cmd As New SQLCommand
cmd.C
cmd.CommandText = "Exec jd_hd " & tm & "," & hd & "," & sta & "," & Ends & ""
Dim Count As Integer= cmd.ExecuteNonQuery()
messagebox.show(count)
每次都报错说'-' 附近有语法错误。
但是我用同样的参数在数据库里运行下面的存储过程是正常的,求帮忙看看是什么情况,抓狂一下午了T T
ALTER PROCEDURE [dbo].[jd_hd](@商品条码 Varchar(20), @活动力度 Varchar(20),@活动开始时间 Varchar(20),@活动结束时间 Varchar(20))
AS
BEGIN
IF OBJECT_ID (N'jd_detail', N'U') IS NOT NULL
DROP TABLE jd_detail
Declare @S Varchar(8000)
select @s='Select [jd_kc].商品条码,[jd_kc].地区,[jd_xl].库存,[jd_xl].在途,[jd_xl].已下单,[jd_xl].未下单,[jd_xl].[7日],[jd_xl].[14日],[jd_xl].[28日],avg([jd_kc].库存减量) as ['+@活动力度+'_'+@活动开始时间+'至'+@活动结束时间+'] into jd_detail'
select @s=@s+' fr om ([jd_kc] left join promote on [jd_kc].商品条码=promote.商品条码 and promote.平台=''京东'' and 活动力度='''+@活动力度+''') left join [jd_xl] on [jd_kc].商品条码=[jd_xl].商品条码 and [jd_kc].地区=[jd_xl].地区'
select @s=@s+' where [jd_kc].商品条码='''+@商品条码+''' and datediff(d,'''+ @活动开始时间+''',[jd_kc].统计日期)>=0 and datediff(d,[jd_kc].统计日期,'''+ @活动结束时间+''')>=0'
select @s=@s+' group by [jd_kc].商品条码, [jd_kc].地区,[jd_xl].库存,[jd_xl].在途,[jd_xl].已下单,[jd_xl].未下单,[jd_xl].[7日],[jd_xl].[14日],[jd_xl].[28日]'
print @S
EXEC(@S)
END