Link to home
Start Free TrialLog in
Avatar of cookster26
cookster26

asked on

concatenation and selecting alpha range in SQL

Hi,

I am programming in visual basic and am having trouble with a couple of queries. They must work against access and oracle. The problem is, as I am working off site I only have access and do not know if what I am doing will work against oracle as well.

Problem 1 - concatenation.

I need to select from 2 separate db fields and concatenate them as one field in the query results. So I want surname and initials to be selected as name.

This works in Access:
select [surnamefield] + ' ' + [initialsfield] as name from....

will this work in oracle as well ?

Problem 2 - select alpha range.

The customer's office is split by surname of their customers. So miss smith deals with all customers whose surname is in range beginning A to BL. If she needs to print all pertinent items for that day for her whole alpha range the sql to do this in access is:

select * from [table] where [surnamefield] >= 'A%' and [surnamefield] <= 'BL%'

again would this work in oracle ?

thanks for your help
Avatar of Arthur_Wood
Arthur_Wood
Flag of United States of America image

in ORACLE, the concatenation operator is ||, not + so in ORACLE, the query would look like

select [surnamefield] || ' ' || [initialsfield] as name from....


Since yoou appear to be using ADO for the Database connection, the % character as the Wildcard in the SQL will work in ORACLE as in Access.

AW
Avatar of cookster26
cookster26

ASKER

I am using ODBC to connect to the databases.

It has been suggested by a colleague that I investigate fn concat for the concatenation. I have looked this up on the net and it seems like this might be the way to go for that problem.

Can anyone help with the alpha-range problem ???
Avatar of Lowfatspread
i'd suggest that you code it as a between should be much faster....

e.g.

A - Bl

surname between 'A' and 'BLZZZZZZZZZZZZZZZZZZZ'    (z's to the length of the column


I agree that coding it as a 'between' is faster,
but this might cause problems if your field is defined as varChar.
So the between solution is only a good idea if used with a Char field with fixed length.
The problem with entering BLZZZZZZZZZ to length of string is the "alpha-split" range will be input in a text box by the user. I do not wish for them to have to type this sort of entry. What I am doing is taking the entry from the text box and doing a VB "split" on it and then the arrsplit(0)  is the character that all results have to be greater than and arrsplit(1) is the character that all resulats have to be less than.

I've managed to get to a machine with Oracle on and tested this yesterday using parameters A-BL. It returned all rows correctly EXCEPT the one row that had a surname beginning BL. (So instead of returning 35 rows it returned 34). For some reason doing A-BL was not inclusive.

I also tried between and this was the same...... how can I get it to be inclusive without the using having to type the ZZZZZ's ??
Ok here is the solution:

strSQL = "Select {fn concat([surname field], {fn concat('  ', [initials field])})} as name, [servicenumber field] as serno " & _
                  " FROM [table name] " & _
                  " WHERE {fn substring([surname field],1," & _
Len(larrAlphaSplitVals(0)) & ")} >= '" & larrAlphaSplitVals(0) & "' " & _
                  " AND {fn substring([surname field],1," & _
Len(larrAlphaSplitVals(1)) & ")} <= '" & larrAlphaSplitVals(1) & "' " & _
                  " ORDER BY [surname field]"

this has been confirmed as working in access and oracle.

how can I get my points back ?? This was my first post on this forum and as no-one from here helped me, I don't think I should allocate any points.. .... is that how things work here ?
ASKER CERTIFIED SOLUTION
Avatar of ee_ai_construct
ee_ai_construct
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial