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
 using column name in 'LIKE' clause

Author  Topic 

kshyamasagar
Starting Member

6 Posts

Posted - 2006-12-28 : 14:10:56
Hi i want to join two tables basing on like condition of the column values of two tables.
My query is like this:

select
pc_assign_worklist.pxRefObjectInsName AS "pxRefObjectInsName",
pc_assign_worklist.pxUrgencyAssign AS "pxUrgencyAssign",
pc_assign_worklist.pyLabel AS "pyLabel",
pc_assign_worklist.pyAssignmentStatus AS "pyAssignmentStatus",
pc_assign_worklist.pxAssignedOperatorID AS "pxAssignedOperatorID" ,
pc_assign_worklist.pxCreateDateTime AS "pxCreateDateTime" ,
pc_assign_worklist.pxCreateOpName AS "pxCreateOpName",
pc_index_workparty.MemberIdentifier AS "MemberIdentifier",
pc_index_workparty.LastName AS "Last Name",
pc_index_workparty.FirstName AS "First Name",
pc_index_workparty.pxInsName AS "pxInsName"
from
dbo.pc_assign_worklist, dbo.pc_index_workparty
where
pxAssignedOperatorID ='dasxkx1'
AND pc_index_workparty.pzInsKey Like '%'+pc_assign_worklist.pxRefObjectInsName+'%' ORDER BY pxUrgencyAssign DESC

-----------

i want to compare the two columns of two tables using like or contains clause as column1 in table a has value like "hi i am" where as column2 in table2 has value "hi". I need help on how to accomplish this.


snSQL
Master Smack Fu Yak Hacker

1837 Posts

Posted - 2006-12-28 : 14:40:26
So what happens when you run that query, what is your question?
Go to Top of Page

Jeff Moden
Aged Yak Warrior

652 Posts

Posted - 2006-12-29 : 10:05:34
If "table2" is the pc_index_workparty table, then just reverse the lookup...

AND pc_assign_worklist.pxRefObjectInsName Like '%'+pc_index_workparty.pzInsKey +'%'

Of course, if the columns are CHAR or NCHAR instead of VARCHAR or NVARCHAR, that could be the problem.

You might also want to crack open BOL and read about a thing called "table aliases" or "Aliases" to simplify your code a bit...

--Jeff Moden
Go to Top of Page

kshyamasagar
Starting Member

6 Posts

Posted - 2006-12-29 : 16:16:48
quote:
Originally posted by snSQL

So what happens when you run that query, what is your question?



i got that query working. No problem. Thanks
Go to Top of Page
   

- Advertisement -