Solved

Query a SQL server from VBScript

Posted on 2009-07-15
1
829 Views
Last Modified: 2012-05-07
Is it possible to Query a SQL server from VBScript, get the sql server to return a boolean value to the vbscript and then use an if statement in the VBScript to act upon that returned value?
0
Comment
Question by:ict-torquilclark
1 Comment
 
LVL 67

Accepted Solution

by:
sirbounty earned 500 total points
ID: 24865944
Certainly...some sample code for you - of course, you'll need to adjust it to your criteria
If GetBoolean Then

  'Execute some code for a true return

Else

  'Execute otherwise

End If
 

Function GetBoolean()

Dim conn : Set conn = CreateObject("ADODB.Connection")

strCnx = "Driver={SQL Server];Server=SQL-Server7;Database=MyDatabase;user id=SomeID;password='password';" 'You can also use trusted connection...

conn.Open strCnx

Dim cmd : Set cmd = CreateObject("ADODB.Command")

Set cmd.ActiveConnection = conn
 

Dim rs : Set rs = CreateObject("ADODB.RecordSet")

rs.Open "Select MyBoolean From Table1 Where ValueData = SomeCriteria", conn
 

If Not rs.EOF Then GetBoolean = True

rs.Close

End Function

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we want to have a look at the directory attributes which are used by Microsoft to store the so called Security Identifiers (SID). These SIDs plays an important role in delegating and granting permissions and in authentication of trus…
This is pretty cool.  The purpose of this VB Script is to help you document where JAR (Java ARchive) files and specifically java class files are located so that you can address issues seen with a client or that you can speak intelligently with a dev…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now