Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

VBSCRIPT SQL Query issue Multiple Line Variable

Posted on 2014-04-11
7
Medium Priority
?
1,774 Views
Last Modified: 2014-04-11
Hello,

I have this script I wrote to track users when they log onto AD for a future project.  The SQL portion does a IF THEN ELSE scenario the issue is my vbs script is returning an error:

Incorrect Syntax near 'UPDATE logons SET Timestamp=GETDATE() WHERE Username='
Code: 80040E14

I checked the syntax of Line 27 which is the beginning of the query statement so I dont know which part I have wrong.

I attached the error and the VB script.

Thanks!
logons-error.vbs
vberror.png
0
Comment
Question by:smyers051972
  • 4
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
gplana earned 2000 total points
ID: 39994858
I think this is the line which is not ok:

myCommand.CommandText = "IF EXISTS (SELECT * FROM logons (nolock) WHERE Username='" & UserString & "')'" &_
	+ " UPDATE logons SET Timestamp=GETDATE() WHERE Username='" & UserString & "')'" &_
	+ " ELSE" &_
	+ " INSERT INTO [logons] (Computername,Username,Timestamp,Action) VALUES ('" & DomainString & "','" & UserString & "', GETDATE(),'LOGON')"

Open in new window


I would do this:

myCommand.CommandText = "IF EXISTS (SELECT * FROM logons (nolock) WHERE Username='" & UserString & "')" &_
	+ " UPDATE logons SET Timestamp=GETDATE() WHERE Username='" & UserString & "')" &_
	+ " ELSE" &_
	+ " INSERT INTO [logons] (Computername,Username,Timestamp,Action) VALUES ('" & DomainString & "','" & UserString & "', GETDATE(),'LOGON')"

Open in new window

0
 
LVL 1

Author Comment

by:smyers051972
ID: 39994894
It still complained about a syntax error near )
0
 
LVL 27

Expert Comment

by:Shaun Kline
ID: 39994909
The update line has a parenthesis at the end that is not needed.
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 1

Author Comment

by:smyers051972
ID: 39994924
ok one sec :)
0
 
LVL 1

Author Comment

by:smyers051972
ID: 39994931
Didnt work could you repost code? sorry!
0
 
LVL 15

Expert Comment

by:gplana
ID: 39994968
Try to put the string on a variable, then print the variable, then try to execute directly on SQL-Server. This is the usual way to debug SQL queries
0
 
LVL 1

Author Closing Comment

by:smyers051972
ID: 39995005
Thanks for the help!
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.
Simple Linear Regression
Suggested Courses

824 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