?
Solved

Query a SQL server from VBScript

Posted on 2009-07-15
1
Medium Priority
?
855 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Hello again, all.  For those of you that have been following along, you'll know that this is my third article on this topic (though it is not Part III).  This article is sort of remedial, and probably the topic with which I should have started the s…
Over the years I have built up my own little library of code snippets that I refer to when programming or writing a script.  Many of these have come from the web or adaptations from snippets I find on the Web.  Periodically I add to them when I come…
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses

764 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