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
 select with like

Author  Topic 

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-09-18 : 04:00:38
Hi.
I've wrote these 2 queries:

SELECT a.product_id AS Expr1
FROM dbo.tbl_product_vendor a INNER JOIN
dbo.name$ b ON a.vendor_code = b.product_vendor_code AND a.vendor_code = b.product_vendor_code

AND

SELECT product_id AS Expr1
FROM dbo.tbl_product_vendor
WHERE (vendor_code IN
(SELECT product_vendor_code
FROM name$))

I didnt get any errors,but the result is not what I want because the vendor_code values on tbl_product_vendor its not excatly match with the values on name$.product_vendor_code.
for instance:

tbl_product_vendor.vendor_code = 'BL3300B.432'
but
name$.product_vendor_code = 'BL3300B'

which means the values on tbl_product_vendor.vendor_code contains the values on name$.product_vendor_code (values on vendor_code have some more letters than values on product_vendor_code)

I thought about adding LIKE for tbl_product_vendor.vendor_code
but I dont know how.
would u please help me with that?
thanks


madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-18 : 04:53:13
SELECT a.product_id AS Expr1
FROM dbo.tbl_product_vendor a INNER JOIN
dbo.name$ b ON a.vendor_code like b.product_vendor_code+'%' AND a.vendor_code = b.product_vendor_code


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

a.ashabi
Posting Yak Master

117 Posts

Posted - 2008-09-18 : 14:09:30
thanks a lot u gave me the hint & I did it this way:

SELECT dbo.tbl_product_vendor.product_id AS Expr1
FROM dbo.tbl_product_vendor CROSS JOIN
dbo.name$
WHERE (dbo.tbl_product_vendor.vendor_code LIKE '%' + dbo.name$.product_vendor_code + '%')

It worked.
thanks a lot
Go to Top of Page
   

- Advertisement -