Link to home
Start Free TrialLog in
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.
Avatar of Brook Braswell
Brook Braswell
Flag of United States of America image

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
Avatar of srikanthreddyn143
srikanthreddyn143

What does it mean by formulate?
where do you see formulate ?
ASKER CERTIFIED SOLUTION
Avatar of Brook Braswell
Brook Braswell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
for GetDate = 2012-05-24 08:45:33.384
the query would result  2405201284533384
Avatar of 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
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of mossmis

ASKER

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

ie. RS.Close

?
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial