473,387 Members | 1,481 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.

How to use the MID function using the Query Builder in VB.NET

Ok, I have a Field that has a combination of letter C and a Number that
increments by one.

example:
C1
C2
C3
C4
C5
C6
C7
C9
C9
C10
C11 ...

I would like to find the Maximun number using the query builder. I tried
using the Substring function but it didnt work, I also tried the LEFT and
RIGHT functions but didnt work for me.

I tried using the MID function but it gave an error saying 'MID' is not a
recognized function name.
Please I just would like to find any way to get the highest numer after the
letter.

Example: if I have C1 thru C34 I wold like the query to give me 34 as the
result.

Thanks for any suggestions.
Nov 21 '05 #1
6 5702
Eduardo78 wrote:
I would like to find the Maximun number using the query builder. I
tried using the Substring function but it didnt work, I also tried
the LEFT and RIGHT functions but didnt work for me.


Assuming this is T-SQL you're using (for a SQL-Server query), you can do it
using SubString.

The easiest way is to get it to return a large number of characters,
starting at character no. 2. Because there aren't enough characters in the
string, it'll just return whatever characters are available, which will be
the remainder of the string.

For example:

SELECT SUBSTRING('C1', 2, 99)
Result is '1'
SELECT SUBSTRING('C234', 2, 99)
Result is '234'

Hope that helps,

--

(O)enone
Nov 21 '05 #2
If the records always will contain one letter at the beginning you can use
this query (tested on sql server 2000):

select max(cast(substring(YourField,2,len(YourField)-1) as integer))
FROM YourTable

hth Peter
"Eduardo78" <Ed*******@discussions.microsoft.com> schreef in bericht
news:37**********************************@microsof t.com...
Ok, I have a Field that has a combination of letter C and a Number that
increments by one.

example:
C1
C2
C3
C4
C5
C6
C7
C9
C9
C10
C11 ...

I would like to find the Maximun number using the query builder. I tried
using the Substring function but it didnt work, I also tried the LEFT and
RIGHT functions but didnt work for me.

I tried using the MID function but it gave an error saying 'MID' is not a
recognized function name.
Please I just would like to find any way to get the highest numer after the letter.

Example: if I have C1 thru C34 I wold like the query to give me 34 as the
result.

Thanks for any suggestions.

Nov 21 '05 #3
Eduardo,
This sounds like a database question? Are you asking for an SQL method of
doing it? SQL for which database, SQL Server, Access, AS/400, Oracle, DB2,
FoxPro?
In VB.NET itself I would do something like:

Dim values() As String = {"C1", "C2", "C3", "C4", "C5", "C6", "C7",
"C9", "C9", "C10", "C11"}
Dim min As Integer = Integer.MaxValue
Dim max As Integer = Integer.MinValue
For Each value As String In values
max = Math.Max(max, CInt(value.Substring(1)))
min = Math.Min(min, CInt(value.Substring(1)))
Next
Debug.WriteLine(min, "min")
Debug.WriteLine(max, "max")

Hope this helps
Jay

"Eduardo78" <Ed*******@discussions.microsoft.com> wrote in message
news:37**********************************@microsof t.com...
| Ok, I have a Field that has a combination of letter C and a Number that
| increments by one.
|
| example:
| C1
| C2
| C3
| C4
| C5
| C6
| C7
| C9
| C9
| C10
| C11 ...
|
| I would like to find the Maximun number using the query builder. I tried
| using the Substring function but it didnt work, I also tried the LEFT and
| RIGHT functions but didnt work for me.
|
| I tried using the MID function but it gave an error saying 'MID' is not a
| recognized function name.
|
|
| Please I just would like to find any way to get the highest numer after
the
| letter.
|
| Example: if I have C1 thru C34 I wold like the query to give me 34 as the
| result.
|
| Thanks for any suggestions.
Nov 21 '05 #4
The Mid function is available by referencing the Microsoft.VisualBasic
namespace.

Disclaimer: I make no value judgement as to its use (and will not
participate in any ensuing holy war).

David Anton
www.tangiblesoftwaresolutions.com
Home of the Instant C# VB.NET to C# converter
and the Instant VB C# to VB.NET converter

"Eduardo78" wrote:
Ok, I have a Field that has a combination of letter C and a Number that
increments by one.

example:
C1
C2
C3
C4
C5
C6
C7
C9
C9
C10
C11 ...

I would like to find the Maximun number using the query builder. I tried
using the Substring function but it didnt work, I also tried the LEFT and
RIGHT functions but didnt work for me.

I tried using the MID function but it gave an error saying 'MID' is not a
recognized function name.
Please I just would like to find any way to get the highest numer after the
letter.

Example: if I have C1 thru C34 I wold like the query to give me 34 as the
result.

Thanks for any suggestions.

Nov 21 '05 #5
Thanks a lot, It worked great.
you just made my day!

"Peter Proost" wrote:
If the records always will contain one letter at the beginning you can use
this query (tested on sql server 2000):

select max(cast(substring(YourField,2,len(YourField)-1) as integer))
FROM YourTable

hth Peter
"Eduardo78" <Ed*******@discussions.microsoft.com> schreef in bericht
news:37**********************************@microsof t.com...
Ok, I have a Field that has a combination of letter C and a Number that
increments by one.

example:
C1
C2
C3
C4
C5
C6
C7
C9
C9
C10
C11 ...

I would like to find the Maximun number using the query builder. I tried
using the Substring function but it didnt work, I also tried the LEFT and
RIGHT functions but didnt work for me.

I tried using the MID function but it gave an error saying 'MID' is not a
recognized function name.
Please I just would like to find any way to get the highest numer after

the
letter.

Example: if I have C1 thru C34 I wold like the query to give me 34 as the
result.

Thanks for any suggestions.


Nov 21 '05 #6
> Disclaimer: I make no value judgement as to its use (and will not
participate in any ensuing holy war).

LOL
Nov 21 '05 #7

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

Similar topics

4
by: Lucky | last post by:
I have a vb.net windows app that connects to an access database. The database has 1 table. One of the columns is called "Address". A user enters any address into a textbox (txtValue) then clicks...
10
by: Hank1234 | last post by:
Can I use one Data Adapter and one Command Builder to update amny tables? Currently in my data adapter I query two tables and fill them into two tables in a data set. When I make a change to a...
7
by: Bob | last post by:
Currently I am using this statement to translate 3 fields in my db thru Visual Basic. I import the data from one table to another then call the IFF statements and the NewDate to translate the...
4
by: Mark Reed | last post by:
HI all, I have an Access XP database which on the whole, uses information pasted into 1 table from a text file. I then have another query which uses the 'Mid' function to break it down. One of the...
0
by: sales | last post by:
I am glad to present to the community of this group the new version of our component intended for visual building of SQL queries via an intuitive interface - Active Query Builder...
4
by: Daz Talbot | last post by:
Hi there Does anyone know if it is possible to invoke the SQL Server Query Builder from within a VB.NET program. I'd like to have query building functionality within my application. Thanks...
5
by: teddysnips | last post by:
I have to write an application to do some data cleansing. It's a Contact database, but over a number of years there are multiple companies which are all essentially the same entity. For each...
13
by: john | last post by:
I have table User-App and table App Profile User-App App Profile IDuser IDApp IDApp 1 34 34 1 45 45 2 34 2 45 2 90 3 34
4
by: AXESMI59 | last post by:
I created a query in the Access Query Builder that I modified to use with VBA Code so I could reuse it for any record I choose. The one that I created with the Access Query builder works beautifully...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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...

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.