Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login




Remember Me
Forgot Password?
Join Us!

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Donate Today!

Do you enjoy these
technical forums?
Donate Today! Click Here

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.
Jobs from Indeed

Link To This Forum!

Partner Button
Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

priyanthan (Programmer) (OP)
22 Mar 10 15:35
I need to join two tables, but the issue is there is no similar columns to join. what i mean is;

table 1
name                          type    notes
----                          ----    ------------
12345678-22556                3601    sample notes
123123123-22555               3601    sample notes
12345678123456-22556          3602    sample notes

table 2

siteid                        location
-------                       --------  
12345678                      Toronto
123123123                     Toronto

i need to join table 1 with table 2 on name and siteid.
In table 1 the characters upto "-" is the siteid.

Can someone help me with this.

Thanks in advance.
papadba (MIS)
22 Mar 10 15:59
Suggest table1 be properly defined. . .

With the current definition, you could also do this inside a program (read table1, build the siteid into a variable, read table2).

 
blom0344 (TechnicalUser)
23 Mar 10 3:42
Use combo of substr and posstr to purge the siteid from the name in table 1. In order to compare you will need to make sure that you have same datatype between join columns, so use the INT function to make an integer of the partial string from name from table 1.

Ties Blom
 
 

priyanthan (Programmer) (OP)
23 Mar 10 10:09
Hi blom0344,

I'm new to this, so can you please give an example how to use the substr and posstr in SQL.

Thanks a lot.  
MarcLodge (Programmer)
23 Mar 10 18:41
priyanthan,
The POSSTR function returns the position of a character (or string) in another string. For instance:
SELECT POSSTR('ABC-DEF','-')
would return the value 4.

The SUBSTR function returns a portion of a string dependant on the parameters given in the SUBSTR function. For instance:
SELECT SUBSTR('ABC-DEF',2,2)
would return the value 'BC' (position 2 for 2 characters)

What Ties is alluding to is a WHERE clause that uses POSSTR on table 1, combined with SUBSTR in order to give you the start and end of the key, dropping off everything after the '-', and then linking that with table 2.

If you need further help, let us know.

Marc
Ps - I haven't given you the complete answer as you said that you were new to this, and I believe that you will find a good deal of satisfaction when you work this slightly unusual problem out yourself.   
blom0344 (TechnicalUser)
24 Mar 10 4:11
And you will find all you need here:

http://mysite.verizon.net/Graeme_Birchall/id1.html

The 'famous' SQL cookbooks, an endless source of reference  :)

Ties Blom
 
 

priyanthan (Programmer) (OP)
26 Mar 10 13:35
Thanks Marc,

that helped me a lot.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Back To Forum

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close