473,406 Members | 2,620 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,406 software developers and data experts.

Join zero padded char to varchar

Having a brain fart and can't figure this out...
I have 2 databases I need to join:

db1.customer.customer_no char(15) right justified, zero padded
sample customer numbers:
000000000000001
000000000000010
000000000000234
000000000012345

db2.customer.customer_no varchar(20) left justified, no padding
sample customer numbers:
1
10
234
12345

How do I join tables on customer_no? Use cast, convert? Strip zeroes from
db1 table?

Thanks.
May 31 '08 #1
2 3868
You can do:

1). db1.customer.customer_no = RIGHT('000000000000000' +
db2.customer.customer_no, 15)

The above will no be able to utilize index on db2.customer.customer_no.

2). CAST(CAST(db1.customer.customer_no AS INT) AS VARCHAR(20)) =
db2.customer.customer_no

This one will not use index on db1.customer.customer_no.

You can create a view (or add computed column) to perform the above on one
of the tables, and then index the transformed column.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

May 31 '08 #2
Thank you. Both options work.
"Plamen Ratchev" <Pl****@SQLStudio.comwrote in message
news:DN******************************@speakeasy.ne t...
You can do:

1). db1.customer.customer_no = RIGHT('000000000000000' +
db2.customer.customer_no, 15)

The above will no be able to utilize index on db2.customer.customer_no.

2). CAST(CAST(db1.customer.customer_no AS INT) AS VARCHAR(20)) =
db2.customer.customer_no

This one will not use index on db1.customer.customer_no.

You can create a view (or add computed column) to perform the above on one
of the tables, and then index the transformed column.

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Jun 1 '08 #3

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

Similar topics

0
by: Pete | last post by:
hello i am a novice at database design and i'm having trouble doing a multi join in mysql, i was able to do a inner join with just the venues and productions tables below like so SELECT...
3
by: kj | last post by:
When I run the attached query, I get duplicates when there is one to many relationship between tableA and tableB. The query, tested schema and the result is attached. Sorry for the long post. ...
6
by: Rowan | last post by:
Hello, I am having a problem with a join. Either I am just not seeing the obvious, it isn't possible, or I need to use a different approach. I have an application with a vsflexgrid that needs...
6
by: Rowland | last post by:
Hi, I've got a field that stores numeric values, representing a tracking number. I've also got a stored procedure that will extract this field and return it to a client. However, I would like to...
4
by: Andrew S | last post by:
Hello Mr. Expert: - I have 3 tables in mysql in MyISAM table format, I am using mysql4.0 on freebsd5.3 - producttbl, productdetailentbl, pricetblN - they all have "productid" as the Primary KEY....
18
by: Dave | last post by:
Guys I am really stuck on this one. Any help or suggestions would be appreciated. We have a large table which seemed to just hit some kind of threshold. They query is somewhat responsive when...
5
by: ltansey | last post by:
I have a problem concerning a join statement query, the two table are called PublicHouse & PublicHouseBeer, below are the following tables are there attributes; PublicHouse Table create table...
2
by: ltansey | last post by:
Simple Join Statement Help -------------------------------------------------------------------------------- I have a problem concerning a join statement query, the two table are called...
2
by: Artie | last post by:
Having a brain fart and can't figure this out... I have 2 databases I need to join: db1.customer.customer_no char(15) right justified, zero padded sample customer numbers:...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.