Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Incrementing code to add code Expand / Collapse
Author
Message
Posted Wednesday, March 20, 2013 12:25 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, September 7, 2013 5:18 AM
Points: 25, Visits: 61
Hi,

I am trying to join the table to itself many times on a condition. Is there a way to automate number of joins based on count of something from another table?

Any help appreciable!

Thanks,
Akber.
Post #1433014
Posted Wednesday, March 20, 2013 3:37 AM
Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Today @ 3:00 AM
Points: 575, Visits: 3,348
are you doing something that a Recursive CTE could resolve?

http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/
Post #1433088
Posted Wednesday, March 20, 2013 3:53 AM
SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Friday, July 4, 2014 3:55 AM
Points: 2,836, Visits: 5,062
akberali67 (3/20/2013)
Hi,

I am trying to join the table to itself many times on a condition. Is there a way to automate number of joins based on count of something from another table?

Any help appreciable!

Thanks,
Akber.


Could you please post a bit more details and code you have so far.


_____________________________________________
"The only true wisdom is in knowing you know nothing"
"O skol'ko nam otkrytiy chudnyh prevnosit microsofta duh!"
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
Post #1433103
Posted Wednesday, March 20, 2013 4:31 AM
SSC Rookie

SSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC RookieSSC Rookie

Group: General Forum Members
Last Login: Saturday, September 7, 2013 5:18 AM
Points: 25, Visits: 61
CTE wouldnt work because I am joining the table to itself meaning the field names would be the same and SQL doesnot accept that.

davidandrews13 (3/20/2013)
are you doing something that a Recursive CTE could resolve?

http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/
Post #1433120
Posted Wednesday, March 20, 2013 5:43 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 3:06 AM
Points: 12,880, Visits: 31,804
akberali67 (3/20/2013)
CTE wouldnt work because I am joining the table to itself meaning the field names would be the same and SQL doesnot accept that.

davidandrews13 (3/20/2013)
are you doing something that a Recursive CTE could resolve?

http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/


sql handles that just fine as long as you rememeber to preface every field with it's table name.
SELECT 
T1.*
T2.*
FROM MyTable T1
LEFT OUTER JOIN MyTable T2 On T1.ID = T2.ID +1




Lowell

--There is no spoon, and there's no default ORDER BY in sql server either.
Actually, Common Sense is so rare, it should be considered a Superpower. --my son
Post #1433147
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse