|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, April 23, 2013 10:40 PM
Points: 22,
Visits: 45
|
|
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.
|
|
|
|
|
SSC-Addicted
      
Group: General Forum Members
Last Login: Yesterday @ 10:15 AM
Points: 463,
Visits: 2,714
|
|
are you doing something that a Recursive CTE could resolve?
http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/
|
|
|
|
|
SSCrazy
      
Group: General Forum Members
Last Login: Yesterday @ 2:08 AM
Points: 2,596,
Visits: 4,506
|
|
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
|
|
|
|
|
Grasshopper
      
Group: General Forum Members
Last Login: Tuesday, April 23, 2013 10:40 PM
Points: 22,
Visits: 45
|
|
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/
|
|
|
|
|
SSChampion
        
Group: General Forum Members
Last Login: Today @ 7:30 AM
Points: 11,791,
Visits: 28,070
|
|
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
|
|
|
|