0

I am trying to run a script on Task Scheduler to update a column in my database every 1 hour.

I have table vw_invoices and a column ExportLock with a default value of 0 which is "unlocked".

I want to run a query to update ExportLock to 1. Currently I am running

update Worldwide.dbo.vw_Invoices 
set ExportLocked = 1

I really appreciate your help.

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Frank
  • 131
  • 3
  • 3
  • 15
  • Your question does not tell us what you need help with!? Which part is not working for you? – David Rushton Jan 16 '17 at 16:15
  • I am trying to create a script with task schduler to run every hour in my SQL server database and update my vw_invoices from unlock to luck. currently i update it manually by running script Worldwide.dbo.vw_Invoices set ExportLocked = 1 how can i create a task scheduler to do this for me ? – Frank Jan 16 '17 at 16:37
  • @TheGameIsWar has provided a nice answer below. Have you had a chance to try that out yet? – David Rushton Jan 16 '17 at 16:54
  • yes I did the as he recommended sqlcmd -S \ -i (inside MyScript.sql I have 'update Worldwide.dbo.vw_Invoices set ExportLocked = 1' ) Created textfile name myoutput created a task schedler to run this, but didn't work. – Frank Jan 16 '17 at 17:32
  • 1
    Try: `sqlcmd -S sf-Frank\sql2012 -i C:\MyScript.sql`. You don't need the angle quotes. – David Rushton Jan 16 '17 at 17:54
  • For more on SQLCmd check out the [documentation](https://msdn.microsoft.com/en-GB/library/ms162773.aspx?f=255&MSPPError=-2147217396). – David Rushton Jan 16 '17 at 17:54

2 Answers2

3

USE SQLCMD along with windows task scheduler to mimic SQL Agent on SQL Server Express:

sqlcmd 
    -S <ComputerName>\<InstanceName> 
    -i <c:\MyScript.sql>
    -o <c:myutput.txt

Keep the above in a notepad and save it as .BAT file and schedule through task scheduler

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
TheGameiswar
  • 27,855
  • 8
  • 56
  • 94
0

I found what I was looking for and here is what I did worked great, I appreciate everyone's help

Community
  • 1
  • 1
Frank
  • 131
  • 3
  • 3
  • 15
  • 1
    Please **[edit]** your post and show the actual code / command / script / input / output as text instead of screenshots. Others can't copy and paste from your images. [See here](http://meta.stackoverflow.com/a/285557/1402846) for details. Thank you. – Pang Jan 27 '17 at 02:56