Solved

Query a SQL server from VBScript

Posted on 2009-07-15
1
834 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Introduction During my participation as a VBScript contributor at Experts Exchange, one of the most common questions I come across is this: "I have a script that runs against only one computer. How can I make it run against a list of computers in …
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Two types of users will appreciate AOMEI Backupper Pro: 1 - Those with PCIe drives (and haven't found cloning software that works on them). 2 - Those who want a fast clone of their boot drive (no re-boots needed) and it can clone your drive wh…

805 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