473,387 Members | 1,597 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Can we use dynamic queries on SQL-SERVER without ADO and without apersistent ODBC Connection?

By "dynamic" I mean the use of an SQL string in code.

This is my best to date:

I do not use ODBC frequently. Is there a simpler way?

Public Sub Whatever()
Dim q As DAO.QueryDef
With DBEngine(0)
..BeginTrans
On Error GoTo WhateverErr
Set q = .Databases(0).CreateQueryDef("Trash" & Format(Now(),
"yyyymmddhhnnss"))
With q
..Connect = "ODBC;DRIVER=SQL SERVER;SERVER=FFDBA-LAPTOP
\SONYLAPTOP;DATABASE=DB_51315;Trusted_Connection=y es"
..SQL = "SELECT * FROM FFDBATransactions WHERE Year([Date]) = 2007 AND
Month([Date]) = 3"
Debug.Print .OpenRecordset().Fields("[Date]").Value ' 2007-03-01
End With
End With
WhateverExit:
DBEngine(0).Rollback
Exit Sub
WhateverErr:
MsgBox Err.Description
Resume WhateverExit
End Sub

Sep 23 '08 #1
1 2014
Mumbling to myself ...
I think this can be more (than the previous) accurately called
dynamic, as it does not use a saved query, unsaved through the
application of a transaction.

Sub whatever2()
Dim w As DAO.Workspace
Dim c As DAO.Connection
Dim r As DAO.Recordset
Set w = DBEngine.CreateWorkspace("", "", "", dbUseODBC)
With w
Set c = .OpenConnection("", _
dbDriverComplete, _
True, _
"odbc;driver={sql server};server=ffdba-laptop
\sonylaptop;database=db_51315;trusted_connection=y es")
With c
Set r = .OpenRecordset( _
"SELECT * FROM FFDBATransactions WHERE Year([Date]) = 2007 AND
Month([Date]) = 3")
End With
End With
Debug.Print r.EOF
End Sub

I think this will not work with DAO < 3.6.

I'm interested because it may give me the kind of direct interaction
that I want with SQL-Server (and that I have with ADO) through ODBC.
Of course, ODBC users may be regular users of such code and I may have
just missed it here.

Yes, I know you're aghast that I haven't released the object
variables. My experience is that such code is unnecessary with DAO >=
3.6.
Sep 23 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: leileili | last post by:
Hello, Hello, I'm new in dynamic SQL query and I have a problem need help. For example: I have a SQL query like this: select hw.family,hw.id where hw.id="1234567"; and I have a txt file...
19
by: Christian Fowler | last post by:
I have a VERY LARGE pile of geographic data that I am importing into a database (db of choice is postgres, though may hop to oracle if necessary). The data is strictly hierarchical - each node has...
6
by: florian | last post by:
Hello, we are running DB2 UDB EEE Version 7.2 Fixpack 12 on a two machine Windows 2000 Advanced Server Cluster in a dss environment. Some dynamic sql statements for etl processes and even some...
7
by: Ford Desperado | last post by:
there is an application which issues a lot of simple dynamic queries against an Oracle database. If CURSOR_SHARING is set to FORCE, Oracle treats dynamic queries as static ones, for instance...
14
by: Ina Schmitz | last post by:
Hello, I would like to get the logical and physical reads for every sql statement executed. Thatfore, I used the command "db2 get snapshot for dynamic sql on <mydatabase>". There, I could see...
4
by: Chris | last post by:
Can't seem to figure out how to do this and have been reading for some time now...... I want to select a row count from a table name in SYSTABLES. This statement does not return what I needed,...
2
by: kalaivanan | last post by:
hi, how far dynamic query built inside stored procedures is efficient than normal queries inside stored procedures. does dynamic query have advantage over ad hoc queries and in what way. kalai...
11
by: Ronald S. Cook | last post by:
I've read a few posts on the stored procedure vs dynamic sql debate. I ran a few performance test for myself and it appears to be a wash. Given that, I'm leaning toward dynamic sql mostly...
11
by: =?Utf-8?B?U3RlZmFuIFdpbGhlbG0=?= | last post by:
Hello, played a little with orcas and went into a problem by building dynamic queries. I want to build a dynamic where clause but only with parameters that are not empty =(TextBox.Text != "")....
0
by: lekhrajm | last post by:
Hi, I want to flush Dynamic Sql CACHE completely in db2 9.1.2 I used command "db2 FLUSH PACKAGE CACHE DYNAMIC". But it lefts some queries in cache. These are fixed queries. It creats problem...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.