September 12, 2012 at 8:43 am
Hello,
I was wondering if someone can help me with this query. I am having issues with having duplicate a2.Id (ParentSFID) for a.Id (ChildSFID). Is there way that I can limit this so it finds only one of the ParentSFID for the ChildSFID.
Thanks!
Here's my query:
SELECT
a.SPID__c AS ChildSPID ,
a.Id AS ChildSFID ,
a.Name AS ChildName ,
a.Type AS ChildType ,
a2.SPID__c AS ParentSPIDDatabase ,
a2.Id AS ParentSFID ,
a2.Name AS ParentName ,
a2.Type AS ParentType
FROM angie.dbo.SPRelationship AS sr WITH ( NOLOCK )
INNER JOIN dbo.Account AS a WITH ( NOLOCK ) ON sr.ToSPID = a.SPID__c
INNER JOIN dbo.Account AS a2 WITH ( NOLOCK ) ON sr.FromSPID = a2.SPID__c
WHERE a.Provider_Type__c = 'physician'
AND a.Type <> 'deleted'
AND a2.Type <> 'deleted'
September 12, 2012 at 9:07 am
I see that you are pretty new around here. Welcome. In order to provide detailed assistance and code we need to have something to work with. The best way to accomplish that is with ddl (create table scripts), sample data (insert statements) and desired output based on your sample data. Take a look at the first link in my signature for best practices when posting questions.
_______________________________________________________________
Need help? Help us help you.
Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.
Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.
Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply