Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: SQL Server ISsue Post Reply Post New Topic
Author Message
rusty
Newbie
Newbie
Avatar

Joined: 07 Mar 2008
Location: United States
Online Status: Offline
Posts: 16
Quote rusty Replybullet Topic: SQL Server ISsue
    Posted: 15 May 2008 at 3:20pm
Hi,
 
I have the Code below
Select a.myeeid, a.coid, a.location, b.cmpcompanyname, c.locdesc, d.ejheeid

from dbo.SecQualList a, dbo.company b, dbo.location c, emphjob d

Where

a.coid = b.cmpcoid and

a.location = c.loccode and

a.myeeid = d.ejheeid and

a.myeeid = '60K4W00000K0'

The issue is a.coid column and c.loccode column have multiple values separated by commas. Is there any ways to do this join with multiple values separated by commas? Any help or guidance will be greatly appreciated.

Thanks

Sony
IP IP Logged
Lugh
Senior Member
Senior Member
Avatar

Joined: 14 Nov 2007
Online Status: Offline
Posts: 377
Quote Lugh Replybullet Posted: 16 May 2008 at 5:04am
Yes.  But, it's not easy, and you really have to know your data.

WHERE
a.coid LIKE '%' + b.cmpcoid + '%'
AND
c.loccode LIKE '%' + a.location + '%'
AND
a.myeeid = d.ejheeid
AND
a.myeeid = '60K4W0000K0'

Now, what happens if there is a b.cmpcoid like 734, and another like 1734?  This will match the two.  One option is to make the LIKE comparison into '%,' + b.cmpcoid + ',%' instead.  Note the commas.  However, this won't pick up 734 in an a.coid like "325, 734, 986" because of the space.  So, you might have to account for that instead.  There could also be an issue if b.cmpcoid has datatype char, as the LIKE could put the trailing spaces in the comparison, when the trailing spaces aren't in a.coid. 

Look carefully at your data.  Run several test queries, and make sure that you are getting back all the data you expect, and only the data you expect.


IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.032 seconds.