title: VBS Script to Execute SQL statement?
body: <p>To open, I have never written a vbs script. I have written many SQL scripts, views, developed databases.  I have written plenty of VBA in Access applications.</p>
  
  <p>For this, I am just trying to set up a SQL script as a VBS script, so the users don't have to go into SSMS to run it.  They can just double-click the VBS script, specify the server and database when prompted, and the quick script will run for them.</p>
  
  <p>This is what I have gotten so far, but I keep getting Microsoft VBScript compilation errors.  The latest one is line 3 char 17, which is on a Dim statement.  Just wanted to see if anyone can tell if I am missing something fundamental to this script, that is preventing it from compiling or processing correctly.</p>
  
  <p>This is the very short script:</p>
  
  <pre><code>Dim conn 
  Set conn = createobject("Adodb.Connection")
  Dim sConnString As String
  Dim SqlStatement As String
  
  sSourceServer = InputBox ("Enter the name of the SQL Server","Enter SQL Server Name","")
      If Len(sSourceServer) = 0 Then
          MsgBox "No SQL Server was specified.", , "Unable to Continue"
          Exit Sub
      End if
  
  sSourceDB = InputBox ("Enter the name of the Law SQL Database","Enter Law SQL DB Name","")
      If Len(sSourceDB) = 0 Then
          MsgBox "No SQL DB was specified.", , "Unable to Continue"
          Exit Sub
      End if
  
  ' Create the connection string.
  sConnString = "Provider=SQLOLEDB;Data Source=" &amp; sSourceServer &amp; "; Initial Catalog=" &amp; sSourceDB &amp; "; Integrated Security=SSPI;"
  
  MsgBox sConnString
  
  ' Open the connection and execute.
  conn.Open sConnString
  conn.CommandTimeout = 900
  
  SqlStatement = "UPDATE [tablename] " &amp; _
                                  "SET UUID = CASE WHEN CHARINDEX('.',[Filename]) &gt; 1 THEN LEFT(CAST([Filename] AS VARCHAR),CHARINDEX('.',[Filename])-1) ELSE [Filename] END " &amp; _
                                  "WHERE [Filename] IS NOT NULL"
  
  conn.Execute(SqlStatement)
  
  conn.Close
  Set rs = Nothing
  SqlStatement = vbNullString
  
  MsgBox "All Done! Go Check your results!"
  </code></pre>
  
  <p>If anyone can help, I'd greatly appreciate it.</p>
  
  <p>Thank you</p>