Solved

Query a SQL server from VBScript

Posted on 2009-07-15
1
849 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
With User Account Control (UAC) enabled in Windows 7, one needs to open an elevated Command Prompt in order to run scripts under administrative privileges. Although the elevated Command Prompt accomplishes the task, the question How to run as script…
This video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

691 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