Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Problems with either joins or selects

Author  Topic 

hlpearl
Starting Member

1 Post

Posted - 2010-08-03 : 16:14:15
I'm having problems getting my select correct! I'm attempting to select from 6-tables, now it's not that bad! The t1 is the parent, t2 (not currently in the select) is a child of t1; t3 is a child of t1; t4 is a child of t1; t5 (not currently in the select) is a child of t1; and lastly t6 is a child of t1. BUT what is happening is my t6 shows up as a child of my t4. I've tried it using multiple selects but I had the same problem. Utilmate goal is create XML that's input into xslt. Here's what my current joins look like:
SELECT t1.Task_name AS title, t1.Task_NO AS task, t3.condition, t3.requirements, t4.STEP_ID AS steps, t4.STEP_ID AS step_id t4.STEP_TX AS step_tx, t6.Actions_ID as actions_id
FROM TASK_DESCRIPTION AS t1
LEFT OUTER JOIN ACTIONS_TASK AS t6 ON t1.TASK_NO=t6.TASK_NO
LEFT OUTER JOIN CONDITIONS_REQUIREMENTS AS t3 ON t1.TASK_NO=t3.TASK_NO
LEFT OUTER JOIN STEPS_OF_TASK AS t4 ON t1.TASK_NO=t3.TASK_NO
WHERE (t1.TASK_NO = @task_no) FOR XML auto, type, ROOT('root'), elements


So my xml looks like this:
-<root>
-<t1>
<title>This is my task name text</title>
<task>This is my task number text</task>
-<t3>
<condition>This is my condition text</condition>
<task>This is my requirements text</task>
-<t4>
<step_id>This is my step_id text</step_id>
<step_tx>This is my step_tx text</step_tx>
-<t6>
<actions_id>This is my actions_id text</actions_id>
-<t4>
<step_id>This is my step_id text</step_id>
<step_tx>This is my step_tx text</step_tx>

My t6 (I think) should only appear one time at the bottom of the tree, but it's appearing between each t4.

I appreciate any and all comments and suggestions!

Thank you in advance for all reply.


   

- Advertisement -