how to join based on substring in sql query

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • venkatesh NV
    New Member
    • Oct 2011
    • 1

    how to join based on substring in sql query

    how to join based on substring in sql query?

    example: i am joind 2 tables first table 175 056 venkatesh
    second table 056 venkatesh NV how can i join....
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32633

    #2
    Unless you can be more specific about the actual requirements I suspect this is not possible.

    The Like comparison allows one whole string to be compared to another sub-string, but you'd need to know exactly what you were trying to compare first. Looking for any unspecified overlap is frankly non-sensical (as that could include something as simple as a space technically).

    Please feel free to clarify the question such that it makes proper sense and we can try to help you.

    Comment

    • nbiswas
      New Member
      • May 2009
      • 149

      #3
      Try this

      Code:
      Declare @table1 table(T1Col1 int,T1Col2 int,T1Col3 varchar(50))
      Insert Into @table1 Select 175, 056,'venkatesh'
      
      Declare @table2 table(T2Col1 int,T2Col2 varchar(50),T2Col3 varchar(50))
      Insert Into @table2 Select 056,'venkatesh','NV'
      
      Select 
      		t1.*
      		,t2.*
      From @table1 t1
      Join @table2 t2
      On t1.T1Col2 = t2.T2Col1
      Result
      ------

      Code:
      T1Col1	T1Col2	T1Col3	T2Col1	T2Col2	T2Col3
      175	56	venkatesh	56	venkatesh	NV
      Hope this helps

      Comment

      Working...