Results 1 to 2 of 2

Thread: SQL Server - JOIN technique

Threaded View

  1. #2
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803

    Re: SQL Server - JOIN technique

    You don't need to split, just convert your ID to string, then search that string in the list.

    Like this:
    Code:
    DECLARE @BrandId_List VARCHAR(MAX)
    SET @BrandId_List = ',123,2354,4567,'
    
    SELECT *
    FROM Sales s
    	INNER JOIN	Products p on c.customerId = p.customerId
    	INNER JOIN	Brands b on p.BrandId = b.BrandId
    WHERE CHARINDEX(',' + CAST(b.brandId AS VARCHAR(10)) + ',', @BrandId_List) > 0
    	OR NULLIF(@BrandId_List, '') IS NULL
    Last edited by CVMichael; Nov 12th, 2009 at 03:37 PM.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width