473,396 Members | 1,895 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.

how to use * in where statment to retreive all record

I am tried to make dynamic sql statement.... But I still face problem I can not retrieve all record thru use if i put me.cb_location.text= *


SELECT * FROM New_Table where Loc_Code Like '" & me.cb_location.Text& " ' ;
Mar 12 '07 #1
1 885
bergy
89
I am tried to make dynamic sql statement.... But I still face problem I can not retrieve all record thru use if i put me.cb_location.text= *

SELECT * FROM New_Table where Loc_Code Like '" & me.cb_location.Text& " ' ;
There are quite a few ways to accomplish this. I think the easiest (and probably worst) way to do this would be to simply replace the * character with a % sign. What happens in your current statement is that you're getting a SQL statement that looks like this:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM  New_Table where Loc_Code Like '*';
SQL does not see '*' in quotes as a wildcard character. You need to use the percent sign to specify a wildcard, so your SQL query should look like:
Expand|Select|Wrap|Line Numbers
  1. SELECT * FROM  New_Table where Loc_Code Like '%';
I'm assuming you're using VB because of the Me keyword so here is a couple lines of VB to put in above your query:

Expand|Select|Wrap|Line Numbers
  1. Dim myLocCodeSearch as String = ""
  2. If cb_location.Text = "*" Then myLocCodeSearch = "%" Else myLocCodeSearch = cb_location.Text
  3. Dim mySQLQuery as String = "SELECT * FROM  New_Table where Loc_Code Like '" & myLocCodeSearch & "';"
The above code would work to replace a single * character with the % sign. If you're wanting to allow someone type in say New* and return New York, New Jersey and New Hampshire you'll need to do a replace which would look like this:

Expand|Select|Wrap|Line Numbers
  1. Dim myLocCodeSearch as String = cb_location.Text
  2. myLocCodeSearch = myLocCodeSearch.Replace("*", "%")
  3. Dim mySQLQuery as String = "SELECT * FROM  New_Table  where Loc_Code Like '" & myLocCodeSearch & "';"
Hope that points you in the right direction!

Adam
Mar 13 '07 #2

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

Similar topics

1
by: joeandtel | last post by:
I have a sql statement that pulls up a certain amount of records according to a requirement. Let's say that 20 records show up. I want to get to the 5th one. Well now I know that I can use the move()...
3
by: eddiec | last post by:
hi everyone, I have a report in an adp that uses aggregate functions in its record source and I am trying to figure out how to filter the records displayed in the report: DoCmd.OpenReport...
1
by: Nothing | last post by:
I am trying to use the sql INSERT INTO statement to add a new record. This is the SQL statement: sql = "INSERT INTO tblpatients(bbid, patientname, orderdate, ordertime, mrnumber, sex, age,...
3
by: tsteinke | last post by:
What is the syntax to refer to your current row in an SQL statement? I am using the "Lookup Wizard" to build a query in a table. How do you refer to the Current Row For instance I have a Table...
4
by: Daniel | last post by:
Hi All, I have question regarding to the read, and update the row in the table. for example: user A, read the row of data from the table. user B, read the row of data from the table as well....
8
by: Belee | last post by:
I have the following code and it is not passing through the Next statement: Private Function IsItemAlreadyAdded() As Boolean Dim drMyRow As DataRow With Me For Each drMyRow In...
3
by: Mike Charney | last post by:
I am having trouble with the where clause in an openreport statement in an Access Data Project. I am using MS-Access 2003 with SQL Svr 2000. The line I am using is: DoCmd.OpenReport...
4
by: Mario Krsnic | last post by:
Hello! I have made an application where user can get reading after entering his name and the name of his partner. I tried to save the names in the database, in the separate table. My solution:...
1
by: zeebiggie | last post by:
Good morning I have a form with the controls in the insert statment below. table1 has an Auto increment primary key hence is omitted in the insert statment and form. Am getting the error It didnt...
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
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...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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.