简体   繁体   English

在存储过程SQL中包括Excel值

[英]Include Excel Value in Stored Procedure SQL

I have a stored procedure that I run through Excel (I have SQL Anywhere ODBC set up) and I need it to look at the value in Cell A1, which will change daily. 我有一个通过Excel运行的存储过程(已设置SQL Anywhere ODBC),我需要它查看单元格A1中的值,该值每天都会更改。

A1 will hold the value =Today() A1将保留值= Today()

My stored procedure SQL currently is: 我的存储过程SQL当前是:

sp_late_billing_mco '2011-10-15' sp_late_billing_mco'2011-10-15'

I want this statement to refer to Cell A1 rather than typing the date every time I go to run it. 我希望此语句引用单元格A1,而不是每次运行时都键入日期。 I've tried different things and I get error messages. 我尝试了不同的操作,但收到错误消息。

Any help would be greatly appreciated. 任何帮助将不胜感激。

您需要将A1的值作为参数提供给存储过程,而不是让SQL Server从电子表格中“读取”该值。

Why don't you change your query and do: 为什么不更改查询并执行以下操作:

DECLARE @Date DATETIME
SELECT @Date = GETDATE()

EXEC sp_late_billing_mco @Date

Or you can change your stored procedure so it doesn't recieve a parameter and put the first two lines of the query above in it. 或者,您可以更改存储过程,使其不接收参数,并将查询的前两行放在其中。

Use VBA to get the value from the cell. 使用VBA从单元格获取值。

DIM MyDate as date
DIM Datestr as string
MyDate = Worksheets("sheet1").Cells(1,1).Value
DateStr = Year(MyDate)&"-"&Month(MyDate)&"-"&Day(MyDate)

Now insert DateStr into the query text and rerun the query. 现在,将DateStr插入查询文本,然后重新运行查询。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM