Run a SQL Seript againt Multiple SQL Server Instances

The VBScript below can be used to read a list of SQL Server instances from a text file and execute a SQL Script againt each of the instances:

Const SERVERLIST = “c:\serverlist.txt”
Const SCRIPT = “c:\errlog.sql”
Const ForReading = 1

Dim sCmd
Dim sLine

Dim oFSO
Dim oFSORead
Dim oShell

Set oFSO = CreateObject(“Scripting.FileSystemObject”)
Set oShell= CreateObject(“WScript.Shell”)

Set oFSORead = oFSO.OpenTextFile(SERVERLIST, ForReading)

Do While Not oFSORead.AtEndOfStream
sLine = trim(oFSORead.ReadLine)
sCmd = “osql -S” & sLine & ” -E -w4000 -i” & SCRIPT & ” -oc:\” & sLine & “.txt”
oShell.Run(sCmd)
Loop

oFSORead.Close

Set oFSO = Nothing
Set oShell = Nothing

Compare two Identical Tables

The script below illustrates how to compare two tables that are identical in order to verify if the values are really the same in both tables:

USE NORTHWIND
GO

SELECT *
INTO dbo.shippers_test
FROM    dbo.shippers

UPDATE dbo.shippers_test
SET     companyname = ‘Speedy’
WHERE   shipperid = 1

UPDATE dbo.shippers
SET     companyname = ‘Feral Shipping’
WHERE   shipperid = 3

SELECT *
FROM    dbo.shippers T1 FULL OUTER JOIN dbo.shippers_test T2
ON      T1.shipperid = T2.shipperid
AND     T1.companyname = T2.companyname
WHERE   T1.shipperid IS NULL
OR      T2.shipperid IS NULL