Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


Incrementing code to add code


Incrementing code to add code

Author
Message
akberali67
akberali67
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
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.
davidandrews13
davidandrews13
SSC Eights!
SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)SSC Eights! (824 reputation)

Group: General Forum Members
Points: 824 Visits: 4447
are you doing something that a Recursive CTE could resolve?

http://blog.sqlauthority.com/2008/07/28/sql-server-simple-example-of-recursive-cte/
Eugene Elutin
Eugene Elutin
Hall of Fame
Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)Hall of Fame (3K reputation)

Group: General Forum Members
Points: 3040 Visits: 5478
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!":-D
(So many miracle inventions provided by MS to us...)

How to post your question to get the best and quick help
akberali67
akberali67
SSC Rookie
SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)SSC Rookie (25 reputation)

Group: General Forum Members
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/

Lowell
Lowell
SSChampion
SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)SSChampion (14K reputation)

Group: General Forum Members
Points: 14931 Visits: 38919
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

--
help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search