MartinSmithhh
Programmer
I am currently working on a message board system. The messages are in a hierarchical arrangement so that each message can have 1 or no Parents and an unlimited number of Child Messages (replies).
I tried using the following query to bring back the details of a particular message and it's Parent and Child messages
However this yielded a strange result (Possibly because I am joining a table to itself twice). When I ran the Query in SQL Enterprise Manager I got the results I expected but when I ran it using
the results were different, I also found that I could change the results returned in the ADODB recordset by altering the order of items in the Query!
So If I changed
Messages1.IsActive AS ChildActive, Messages2.IsActive AS ParentActive
To Read
Messages2.IsActive AS ParentActive, Messages1.IsActive AS ChildActive
(Which shouldn't make any difference) the values returned in RS("ChildActive"
were different!
So I am currently at the stage that I can either get correct values for RS("ChildActive"
Or RS("ParentActive"
depending on which order they are written but not both!
Has anyone else had similar problems and if so how did you resolve them (I looked in the MSDN KB and couldn't see anything related)
I tried using the following query to bring back the details of a particular message and it's Parent and Child messages
Code:
Query = "SELECT Messages1.IsActive AS ChildActive, Messages2.IsActive AS ParentActive, Forums.ForumID, Forums.ForumIsActive, " & _
"Messages.IsActive, Messages.MessageTitle, " & _
"Messages.PostDate, Messages.MessageBody, " & _
"AAMem.UFName + ' ' + AAMem.ULastC AS Name, " & _
"AAMem.UKey, Messages2.MessageID AS ParentID, " & _
"Messages2.MessageTitle AS ParentTitle, " & _
"Messages1.MessageID AS ChildID, " & _
"Messages1.MessageTitle AS ChildTitle " & _
"FROM Messages INNER JOIN " & _
"AAMem ON Messages.Postedby = AAMem.UKey INNER JOIN " & _
"Forums ON " & _
"Messages.ForumID = Forums.ForumID LEFT OUTER JOIN " & _
"Messages Messages2 ON " & _
"Messages.ParentMessage = Messages2.MessageID LEFT OUTER " & _
"JOIN " & _
"Messages Messages1 ON " & _
"Messages.MessageID = Messages1.ParentMessage " & _
"WHERE (Messages.MessageID = " & qM & ")"
However this yielded a strange result (Possibly because I am joining a table to itself twice). When I ran the Query in SQL Enterprise Manager I got the results I expected but when I ran it using
Code:
RS.Open query, Conn, adOpenStatic, adLockReadOnly
the results were different, I also found that I could change the results returned in the ADODB recordset by altering the order of items in the Query!
So If I changed
Messages1.IsActive AS ChildActive, Messages2.IsActive AS ParentActive
To Read
Messages2.IsActive AS ParentActive, Messages1.IsActive AS ChildActive
(Which shouldn't make any difference) the values returned in RS("ChildActive"
So I am currently at the stage that I can either get correct values for RS("ChildActive"
Has anyone else had similar problems and if so how did you resolve them (I looked in the MSDN KB and couldn't see anything related)