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.
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),
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.
What does it mean by formulate?
where do you see formulate ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
for GetDate = 2012-05-24 08:45:33.384
the query would result 2405201284533384
the query would result 2405201284533384
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?
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
That works! One last question, should I get in the habit of closing the connection when I'm done?
ie. RS.Close
?
ie. RS.Close
?
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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),
"AS DateGen"
RS.CursorLocation = adUseClient
RS.Open SQL, cn, adOpenStatic, adLockReadOnly