Avatar of mossmis
mossmis
 asked on

VB6 ADO SQL Server Question

I have the following SQL statement I want to execute from within a VB6 App:

SELECT DATENAME(dd, GETDATE())+
left(CONVERT(VARCHAR(8), GETDATE(), 1),2)+
DATENAME(yyyy, GETDATE())+
DATENAME(hh, GETDATE())+
DATENAME(mi, GETDATE())+
DATENAME(ss, GETDATE()) + right(CONVERT(VARCHAR(23), GETDATE(), 121), 3)
AS DateGen


I am trying to get it to work with ADO and with examples I found on the web, I cannot figure out how to formulate it. I am connecting to SQL server 2008 via ODBC.  All I want to do is  return the "DateGen". Any help would be appreciated.
Visual Basic ClassicMicrosoft SQL Server

Avatar of undefined
Last Comment
Brook Braswell

8/22/2022 - Mon
Brook Braswell

DIM SQL AS STRING
DIM RS AS NEW ADODB.RECORDSET
DIM CN AS NEW ADODB.CONNECTION
CN.OPEN "YOUR CONNECTION TO SQL"

SQL = "SELECT DATENAME(dd, GETDATE())+ " & _
"left(CONVERT(VARCHAR(8), GETDATE(), 1),2)+ " & _
"DATENAME(yyyy, GETDATE())+ " & _
"DATENAME(hh, GETDATE())+ " & _
"DATENAME(mi, GETDATE())+ " & _
"DATENAME(ss, GETDATE()) + right(CONVERT(VARCHAR(23), GETDATE(), 121), 3) " & _
"AS DateGen"

RS.CursorLocation = adUseClient
RS.Open SQL, cn, adOpenStatic, adLockReadOnly
srikanthreddyn143

What does it mean by formulate?
Brook Braswell

where do you see formulate ?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
ASKER CERTIFIED SOLUTION
Brook Braswell

Log in or sign up to see answer
Become an EE member today7-DAY FREE TRIAL
Members can start a 7-Day Free trial then enjoy unlimited access to the platform
Sign up - Free for 7 days
or
Learn why we charge membership fees
We get it - no one likes a content blocker. Take one extra minute and find out why we block content.
Not exactly the question you had in mind?
Sign up for an EE membership and get your own personalized solution. With an EE membership, you can ask unlimited troubleshooting, research, or opinion questions.
ask a question
Brook Braswell

for GetDate = 2012-05-24 08:45:33.384
the query would result  2405201284533384
mossmis

ASKER
Brook1966,

I got the query to run in VB. How do I get it to return the value so I can use it in my program?
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
mossmis

ASKER
That works! One last question, should I get in the habit of closing the connection when I'm done?

ie. RS.Close

?
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.
SOLUTION
Log in to continue reading
Log In
Sign up - Free for 7 days
Get an unlimited membership to EE for less than $4 a week.
Unlimited question asking, solutions, articles and more.