Solved

concatenation and selecting alpha range in SQL

Posted on 2004-04-05
8
524 Views
Last Modified: 2006-11-17
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
0
Comment
Question by:cookster26
8 Comments
 
LVL 44

Expert Comment

by:Arthur_Wood
ID: 10756390
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
0
 

Author Comment

by:cookster26
ID: 10757085
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 ???
0
 
LVL 50

Expert Comment

by:Lowfatspread
ID: 10758866
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


0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 

Expert Comment

by:paul_dewit
ID: 10768329
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.
0
 

Author Comment

by:cookster26
ID: 10772882
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 ??
0
 

Author Comment

by:cookster26
ID: 10773553
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 ?
0
 

Accepted Solution

by:
ee_ai_construct earned 0 total points
ID: 10987066
PAQed, with points refunded (100)

ee_ai_construct - (re-order part number #xm34)
Community Support Moderator
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now