Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Joining Fields From 2 tables with Similiar Data

Status
Not open for further replies.

marshg2078

Programmer
Nov 20, 2003
1
US
I have 2 tables and I'm trying to join the 2 tables so I can get information from both of them. The joining fields have similar information, but do not match exactly. See below...

Table 1
Table - T_Client_FTD_Log
Field - MessageText
Information - Write 'False' to 'z253\motor\sy\253AG2161\cmd\msk_flt_tmp'.

Table 2
Table - trc_tags
Field - Col002
Information - z253\motor\sy\253AG2161\cmd\msk_flt_tmp


I've tried using this query among many other things. I'm not able to figure out how to get a wildcard around my subquery (if its even possible). Am I heading in the correct direction or is there another way to do this? Thanks!

SELECT T_Client_FTD_Log.MessageText
FROM T_Client_FTD_Log
WHERE T_Client_FTD_Log.MessageText LIKE '%z253\motor\sy\253AG2161\cmd\msk_flt_tmp%' AND
T_Client_FTD_Log.MessageText LIKE (SELECT trc_tags.Col002
FROM trc_tags
WHERE trc_tags.Col002 LIKE '%z253\motor\sy\253AG2161\cmd\msk_flt_tmp%')
 
Try this script,

SELECT T_Client_FTD_Log.MessageText
FROM T_Client_FTD_Log
WHERE T_Client_FTD_Log.MessageText LIKE '%z253\motor\sy\253AG2161\cmd\msk_flt_tmp%' AND
T_Client_FTD_Log.MessageText LIKE '%'+ (SELECT trc_tags.Col002
FROM trc_tags
WHERE trc_tags.Col002 LIKE '%z253\motor\sy\253AG2161\cmd\msk_flt_tmp%') +'%'


SQL Server Programmers
 
Change LIKE to SUBSTRING(COLUMN NAME
,STARTING POSITION, ENDING POSITION) this is much faster due to the fact it reduces the amount of characters you actual look at using % compared to SUBSTRING
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top