473,396 Members | 1,725 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,396 software developers and data experts.

dynamic queries

83
I would like to create a form that includes all the variables in my dataset, in which I can select a certain value, or a range of certain values for any amount of variables in one of tables and based on the values I put in the form, it will generate a query.

For example, Lets say my table had four variables
Face Amount AGE Life Expectency Policy Loan


In the form I would like to specify.....lets say.....

Face Amount 100,000-1000000
AGE 70-85
Life Expectency 60-100
Policy Loan (nothing) I want to just leave it blank and thus no criteria will be selected
Apr 10 '07 #1
17 2100
Rabbit
12,516 Expert Mod 8TB
Okay, so what problems are you having?
Apr 12 '07 #2
jl2886
83
Okay, so what problems are you having?
I am not even sure where to begin. HOw do I do it?
Apr 12 '07 #3
Rabbit
12,516 Expert Mod 8TB
There are two routes. One is to rebuild the query definition from code when they want to view the query. Another is to use the form's controls as criteria in the query. This will also require code to make sure the criteria entered is valid in a query.
Apr 12 '07 #4
ADezii
8,834 Expert 8TB
I would like to create a form that includes all the variables in my dataset, in which I can select a certain value, or a range of certain values for any amount of variables in one of tables and based on the values I put in the form, it will generate a query.

For example, Lets say my table had four variables
Face Amount AGE Life Expectency Policy Loan


In the form I would like to specify.....lets say.....

Face Amount 100,000-1000000
AGE 70-85
Life Expectency 60-100
Policy Loan (nothing) I want to just leave it blank and thus no criteria will be selected
What you are requesting is a Criteria Form in which a User can specify multiple criteria relating to several Fields. The Values or Range of Values would be defined by you, the developer. A fairly complex undertaking unless you have had some programming experience.
Apr 12 '07 #5
NeoPa
32,556 Expert Mod 16PB
I would like to create a form that includes all the variables in my dataset, in which I can select a certain value, or a range of certain values for any amount of variables in one of tables and based on the values I put in the form, it will generate a query.

For example, Lets say my table had four variables
Face Amount AGE Life Expectency Policy Loan


In the form I would like to specify.....lets say.....

Face Amount 100,000-1000000
AGE 70-85
Life Expectency 60-100
Policy Loan (nothing) I want to just leave it blank and thus no criteria will be selected
I don't find your question very clear, but on the off-chance that it may be helpful, I'll post a link (Example Filtering on a Form.). If nothing else, it should give you some ideas.
Apr 17 '07 #6
jl2886
83
Hey, I know how to filter a form. Is there anyway to construct a form that creates criteria statements for a query. So far, I have created a query with the fields from a table that I am intersted in. I unbound all of the variables in the form. I then can create a form filter that will filter cases from the query, but that's just the same thing as filtering the main table. How do I create a form...that allows me to input search criteria...then it brings up a query table with the criteria that I specify.

I don't find your question very clear, but on the off-chance that it may be helpful, I'll post a link (Example Filtering on a Form.). If nothing else, it should give you some ideas.
Apr 17 '07 #7
NeoPa
32,556 Expert Mod 16PB
I guess you didn't feel it worthwhile even to look at the thread then?
Apr 18 '07 #8
Rabbit
12,516 Expert Mod 8TB
Hey, I know how to filter a form. Is there anyway to construct a form that creates criteria statements for a query. So far, I have created a query with the fields from a table that I am intersted in. I unbound all of the variables in the form. I then can create a form filter that will filter cases from the query, but that's just the same thing as filtering the main table. How do I create a form...that allows me to input search criteria...then it brings up a query table with the criteria that I specify.
I refer you to posts #4 and #5
Apr 18 '07 #9
Denburt
1,356 Expert 1GB
I would love to try and help but obviously there is a communications issue....

Answer post #4 since I do believe Rabbit is on the right track. Remember though that post #5 is very true also.
Apr 18 '07 #10
jl2886
83
OH NO, I created a search for a form for the database using that link. I already understand it.

I guess you didn't feel it worthwhile even to look at the thread then?
Apr 18 '07 #11
jl2886
83
Here is a sample of the search form I made.
Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckFilter()
  2.     Dim strFilter As String, strOldFilter As String
  3.        strOldFilter = Me.Filter
  4.         If Me.Find_Case_Number > "" Then _
  5.         strFilter = strFilter & _
  6.                     " AND ( [LSI Case Number] LIKE '" & Me.Find_Case_Number & "')"
  7.  
  8.                 If Me.Find_Insured_Name > "" Then _
  9.         strFilter = strFilter & _
  10.                     " AND ([Insured Name]='" & _
  11.                     Me.Find_Insured_Name & "')"
  12.  
  13.     If Me.Find_Policy_Number > "" Then _
  14.         strFilter = strFilter & _
  15.                     " AND ([Policy Number]='" & _
  16.                     Me.Find_Policy_Number & "')"
  17.  
  18.     If strFilter > "" Then strFilter = Mid(strFilter, 6)
  19.     If strFilter <> strOldFilter Then
  20.         Me.Filter = strFilter
  21.         Me.FilterOn = (strFilter > "")
  22.     End If
  23. End Sub
  24.  
This how I think it can be done, but it doesn't seem like anyone wants to help me.
First, create a form with all the fields I want to look at. Unbound them
(hopefully there is a way to create criteria statements for fields that I dont' want to show)
Then create a visual basic code that will input criteria based on the unbound values. the code should be similar to that of the search for a form???
Then create a docommand statement that generates q query based on the criteria specified in the code.

this is a guess, can anyone either, tell me how in words, or give me a sample.

Thanks
Apr 18 '07 #12
Denburt
1,356 Expert 1GB
This how I think it can be done, but it doesn't seem like anyone wants to help me.
as you can see from the number of people that posted in here that this statement isn't true, we are all glad to help but we need to be able to understand just what it is you need or want otherwise we can sit here and guess all day.

As Rabbit stated Post #4 you can change the query def itself (the actual saved query) every time you want to run this but you will also need to replace the where statement every time.
QueryDefs:
http://msdn2.microsoft.com/en-us/library/bb177500.aspx

OR

As Rabbit mentioned you can look at the query in design view and set the criteria for each field that will have criteria to look at your form for the information. Set the criteria in the query as such:
Forms!MyForm!MyControl


Using your code you could make a few changes then
Declare and set your querydef then you should be set.
qdef.sql = strFilter

Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckFilter()
  2.     Dim strFilter As String, strFilter As String
  3. strFilter = " Where"
  4.         If Me.Find_Case_Number > "" Then _
  5.         strFilter = strFilter & _
  6.                     " ( [LSI Case Number] LIKE '" & Me.Find_Case_Number & "') And"
  7.  
  8.                 If Me.Find_Insured_Name > "" Then _
  9.         strFilter = strFilter & _
  10.                     " ([Insured Name]='" & _
  11.                     Me.Find_Insured_Name & "') AND"
  12.  
  13.     If Me.Find_Policy_Number > "" Then _
  14.         strFilter = strFilter & _
  15.                     " ([Policy Number]='" & _
  16.                     Me.Find_Policy_Number & "') AND "
  17.  
  18.     If strFilter > "" Then strFilter = Left(strFilter, len(strFilter)-4)
  19.         Qdf.sql = strFilter
  20.  
  21.     End If
  22. qdf.close
  23. End Sub
Apr 18 '07 #13
jl2886
83
I know everyone is trying to help, but maybe i am not explaining myself. I want to create a form that specifies the criteria of a query. When I click a button a query opens with the criteria and the field values that I specify. A check box, means show field. and the values in the text boxes specify the criteria.

as you can see from the number of people that posted in here that this statement isn't true, we are all glad to help but we need to be able to understand just what it is you need or want otherwise we can sit here and guess all day.

As Rabbit stated Post #4 you can change the query def itself (the actual saved query) every time you want to run this but you will also need to replace the where statement every time.
QueryDefs:
http://msdn2.microsoft.com/en-us/library/bb177500.aspx

OR

As Rabbit mentioned you can look at the query in design view and set the criteria for each field that will have criteria to look at your form for the information. Set the criteria in the query as such:
Forms!MyForm!MyControl


Using your code you could make a few changes then
Declare and set your querydef then you should be set.
qdef.sql = strFilter

Expand|Select|Wrap|Line Numbers
  1. Private Sub CheckFilter()
  2.     Dim strFilter As String, strFilter As String
  3. strFilter = " Where"
  4.         If Me.Find_Case_Number > "" Then _
  5.         strFilter = strFilter & _
  6.                     " ( [LSI Case Number] LIKE '" & Me.Find_Case_Number & "') And"
  7.  
  8.                 If Me.Find_Insured_Name > "" Then _
  9.         strFilter = strFilter & _
  10.                     " ([Insured Name]='" & _
  11.                     Me.Find_Insured_Name & "') AND"
  12.  
  13.     If Me.Find_Policy_Number > "" Then _
  14.         strFilter = strFilter & _
  15.                     " ([Policy Number]='" & _
  16.                     Me.Find_Policy_Number & "') AND "
  17.  
  18.     If strFilter > "" Then strFilter = Left(strFilter, len(strFilter)-4)
  19.         Qdf.sql = strFilter
  20.  
  21.     End If
  22. qdf.close
  23. End Sub
Apr 18 '07 #14
Denburt
1,356 Expert 1GB
The code that I posted is real close to what I think you want did you check out the link and or make anymore changes? I do not mind helping and I even post copy/paste code once in a while but that is rare, I like to help those that are willing to help themselves as you did earlier make an attempt. I like most people here are volunteering to HELP (keyword). My main goal here is to not only see you through an issue but make sure you understand the code used as well.
Apr 18 '07 #15
NeoPa
32,556 Expert Mod 16PB
OH NO, I created a search for a form for the database using that link. I already understand it.
Received and understood :)
I'll come in again here if I'm needed, but it looks like the others have it covered atm.
Apr 19 '07 #16
NeoPa
32,556 Expert Mod 16PB
As far as Dynamic Queries go generally, they can be changed in code by amending (or creating) a SQL string within your code.
This SQL can then be used in one of two ways :
  1. Executed directly.
  2. Saved away into a queryDef (Saved Query) and then executed from there.
QueryDefs can be created from scratch from code but it's usually easier to pop the SQL code into an existing QueryDef. This DOES have the drawback that an operator may not know what to expect from a QueryDef if they come to use it directly as your code may have changed it in the mean-time with specifics, relevant only to the instance when it was changed.
I hope this overview of the situation helps.
Apr 19 '07 #17
jl2886
83
Thank you, everyone. . I have a form with unbound controls with a visual basic code that does all the check filter stuff with qdef. Then I am going to create a button that opens the query. I will post the code soon. Thanks everyone
As far as Dynamic Queries go generally, they can be changed in code by amending (or creating) a SQL string within your code.
This SQL can then be used in one of two ways :
  1. Executed directly.
  2. Saved away into a queryDef (Saved Query) and then executed from there.
QueryDefs can be created from scratch from code but it's usually easier to pop the SQL code into an existing QueryDef. This DOES have the drawback that an operator may not know what to expect from a QueryDef if they come to use it directly as your code may have changed it in the mean-time with specifics, relevant only to the instance when it was changed.
I hope this overview of the situation helps.
Apr 19 '07 #18

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Guinness Mann | last post by:
When you guys talk about "dynamic SQL," to what exactly are you referring? Is dynamic SQL anything that isn't a stored procedure? Specifically, I use ASP.NET to communicate with my SQL Server...
1
by: Kevin Frey | last post by:
Hello, I have a test database with table A containing 10,000 rows and a table B containing 100,000 rows. Rows in B are "children" of rows in A - each row in A has 10 related rows in B (ie. B has...
7
by: Michael C# | last post by:
Is it possible to create Dynamic SQL queries in MySQL, like in SQL Server? i.e., the EXECUTE command or sp_executesql stored procedure in SQL Server. TIA
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...
1
by: Nathan Bloomfield | last post by:
Does anyone know if there is any documentation which relates to Access2k + ? or can anyone help adjust the code? I am having trouble converting the DAO references. TITLE :INF: How to...
3
by: CAD Fiend | last post by:
Hello, Well, after an initial review of my database by my client, they have completely changed their minds about how they want their form. As a result, I'm having to re-think the whole process....
7
by: Ronald S. Cook | last post by:
I've always been taught that stored procedures are better than writing SQL in client code for a number of reasons: - runs faster as is compiled and lives on the database server - is the more...
3
by: creative1 | last post by:
Here is how you create a complex data report that involves parent and child commands and you can update information at runtime. Its pretty straight forward to work with simple queries; however,...
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: 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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.