Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 LIKE between 2 tables

Author  Topic 

JASONPCS
Starting Member

2 Posts

Posted - 2010-05-04 : 03:17:09
Hi,

I am trying to SELECT data from 2 tables where a field in one table is like a field in another.

EG. Select * from STOCKTRAN where STOCKTRAN.REF LIKE ____PURCHTRAN.Num

I know the above is not correct but im guessing similar.

the ____ stands for 4 characters that are in front of the number in PURCHTRAN.num which are not in STOCKTRAN.REF

Any help would be great,

Cheers

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-05-04 : 03:29:18
SELECT *
FROM STOCKTRAN s
JOIN PURCHTRAN p
ON s.REF LIKE '%' + p.Num

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 03:53:26
if you want to look for 4 specific preceding characters you can use

LIKE '____' + p.Num

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

JASONPCS
Starting Member

2 Posts

Posted - 2010-05-04 : 04:22:26
Thanks a million! Bunch of legends!

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-05-04 : 04:28:02
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -