简体   繁体   中英

Trying to Run SQL Stored Procedure in EXCEL Automatically

The below query requires me to manually Set the @begin_date and @end_date manually, then i copy and paste into SQL and Execute.

Use Analytical                                                                                      

Declare @end_date       DATE
,@begin_date        DATE                                                                                        

Set     @begin_date = '11/20/2017'
Set     @end_date = '11/26/2017'    

If Object_ID('Temp_Table_1') is not null
Drop Table Temp_Table_1

The first two temp tables are pulls to get all of the information in correctly, ALSTMF and ALCOVR must both be updated for the table to work!

My goal however is to be able to use a syntax that will generate the date range automatically and give me the same result. so i tried using 'GETDATE' on the same query and it did not generate any result.

Use Analytical                                                                                  
Declare @end_date       DATE
,@begin_date        DATE

SELECT GETDATE() - 7

If Object_ID('Temp_Table_1') is not null
Drop Table Temp_Table_1 

When i ran this query, with other parts of the query, no records was generated. Can anyone please advice me on what to do?

Declare @end_date DATE , @begin_date DATE

Set @begin_date = '20171120' Set @end_date = '20171112'

--the date depend of your laguange, try YYYYmmdd

If Object_ID('Temp_Table_1') is not null Drop Table Temp_Table_1

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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