ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Update Query from Excel VBA module (https://www.excelbanter.com/excel-programming/434741-update-query-excel-vba-module.html)

gcutter

Update Query from Excel VBA module
 
I need to run a query against a SQL DB in Excel so I can use Task Scheduler
and run the Excel File every 6 hours. I created the update query in Access.
SQL Server Name: SQL
Database: Production
Table: Job

Heres the SQL query from Access:
UPDATE Job SET Job.Priority = 0
WHERE (((Job.Job) Like "F*") AND ((Job.Status)="Active") AND
((Job.Priority)0) AND ((Job.Sched_Start) Is Not Null));

joel

Update Query from Excel VBA module
 
Excel should be able to set from the worksheet menu create the query for up
to 3 parameters. when you get to the last menu (the one with finish) select
edit query, then finish. The Query Editor will come up. Press the SQL
button. then edit the SQL to add in your 4 filter.

1) worksheet menu : Data : Import External Data - Import Data - New Database
query

2) Select Access Database and your file.

3) first menu select the columns.

4) 2nd menu set up you filters.

5) go to Finsh menu and proceed as stated above.


Yo can record a macro while performing the query. The Command Text portion
of the query is the SQL.

"gcutter" wrote:

I need to run a query against a SQL DB in Excel so I can use Task Scheduler
and run the Excel File every 6 hours. I created the update query in Access.
SQL Server Name: SQL
Database: Production
Table: Job

Heres the SQL query from Access:
UPDATE Job SET Job.Priority = 0
WHERE (((Job.Job) Like "F*") AND ((Job.Status)="Active") AND
((Job.Priority)0) AND ((Job.Sched_Start) Is Not Null));


gcutter

Update Query from Excel VBA module
 
Nevermind I wrote the Update query on the SQL Server and set it up to run
every morning at 1AM as a Scheduled Job Type T-SQL.

UPDATE Job Set Priority = '0'
From Job
WHERE Status ='Active' and Priority 0 and Job Like 'F%' and Sched_End Is
Not Null


"Joel" wrote:

Excel should be able to set from the worksheet menu create the query for up
to 3 parameters. when you get to the last menu (the one with finish) select
edit query, then finish. The Query Editor will come up. Press the SQL
button. then edit the SQL to add in your 4 filter.

1) worksheet menu : Data : Import External Data - Import Data - New Database
query

2) Select Access Database and your file.

3) first menu select the columns.

4) 2nd menu set up you filters.

5) go to Finsh menu and proceed as stated above.


Yo can record a macro while performing the query. The Command Text portion
of the query is the SQL.

"gcutter" wrote:

I need to run a query against a SQL DB in Excel so I can use Task Scheduler
and run the Excel File every 6 hours. I created the update query in Access.
SQL Server Name: SQL
Database: Production
Table: Job

Heres the SQL query from Access:
UPDATE Job SET Job.Priority = 0
WHERE (((Job.Job) Like "F*") AND ((Job.Status)="Active") AND
((Job.Priority)0) AND ((Job.Sched_Start) Is Not Null));



All times are GMT +1. The time now is 06:55 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com