| |
|
If this is your first visit, be sure to check out the FAQ by clicking the link above.
You may have to register before you can post: click the register link above to proceed.
To start viewing messages, select the forum that you want to visit from the selection below.
|
 |

09-06-06, 17:47
|
|
Registered User
|
|
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
|
|
|
Join Query on a PK
|
|
I am building a small database that is somewhat like a ledger for pricing team here. In a given month the get 15 cases or so. I made the case number my pk. A case number is the pricer's first name and last name then a three digit number. So RB001. Then I have a table that has initials and full names. What I want to do is to be able to rip the RB out and compare that against the table with the names, so the pricers can pull records by their name...
|
|

09-06-06, 18:03
|
|
Registered User
|
|
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
|
|
Try:
Code:
SELECT case_nr[1,2] FROM ...
Don't know if this is standard SQL but it works fine in Informix...
Regards
|
|

09-07-06, 08:42
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
|
|
SUBSTRING(casenumber FROM 1 FOR 2)
also, it will probably help if you would post your questions in the forum specific to your particular database system
this forum is for standard SQL, the language, and while all database systems support standard SQL to one degree or another, it is in the area of functions that support is most sporadic (to say nothing of the availability of many non-standard but quite useful functions in different databases)
|
|

09-07-06, 11:51
|
|
Registered User
|
|
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
|
|
Or simply: SUBSTRING(casenumber, 1, 2)
In M$ Access you may need to use: LEFT(casenumber,1)

__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
|
|

09-07-06, 11:58
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
|
Originally Posted by LKBrwn_DBA
Or simply: SUBSTRING(casenumber, 1, 2)
In M$ Access you may need to use: LEFT(casenumber,1)

|
unless Access automatically doubles up bytes, i would suggest LEFT(casenumber, 2)

|
|

09-07-06, 12:06
|
|
Registered User
|
|
Join Date: Jun 2003
Location: West Palm Beach, FL
Posts: 2,455
|
|
Ooops, yes that was a typo.
__________________
The person who says it can't be done should not interrupt the person doing it. -- Chinese proverb
|
|

09-08-06, 01:41
|
|
Registered User
|
|
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
|
|
Yet some other systems will need
Code:
SUBSTR(casenumber,1,2)
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
|
|

09-08-06, 02:47
|
|
Registered User
|
|
Join Date: Sep 2004
Location: Belgium
Posts: 1,079
|
|
Quote:
|
Originally Posted by rguy84
I made the case number my pk. A case number is the pricer's first name and last name then a three digit number. So RB001.
|
An interesting alternative (especially in terms of performance) could be to define a two-column PK. The first column would then have "RB" and the second one "001", which (1) avoids the costly substring() construct, and (2) allows e.g. having an index on that first column for efficient retrieval. Moreover it's more flexible in that it will easily allow e.g. 3-letter initials in the future without having to change any of your queries (which is not the case now).
__________________
--_Peter Vanroose,
__IBM Certified Database Administrator, DB2 9 for z/OS
__IBM Certified Application Developer
__ABIS Training and Consulting
__http://www.abis.be/
|
|

09-08-06, 16:09
|
|
Registered User
|
|
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
|
|
It is an Access DB. But seeing this was strictly how to pull information from a table USING SQL, I figured it was more appropriate to ask a question directly to the SQL Forum.
Actually it'd be left$(CaseNo,2), but this doesn't work.
Peter - I think I may have to split them up like you said.
|
|

09-08-06, 16:41
|
|
SQL Consultant
|
|
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,524
|
|
Quote:
|
Originally Posted by rguy84
... doo bee doo ... USING SQL ... doo bee doo
|
there is sql, and there is sql, and there is standard sql...
... and then there is access sql
the whole point about what we are telling you is that unless you know the difference between the various types of sql, and how they are likely to vary from standard sql, it would be far better for you if you would post in the specific forum for your specific database
just trying to save you the agro, man

|
|

09-11-06, 12:27
|
|
Registered User
|
|
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
|
|
ok thanks, i'll see what i can do
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|