Show Access DB-content with i.e. WHEN-statement??

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Show Access DB-content with i.e. WHEN-statement??

    I have a database with an autoincrement ID-column and a ParentID-column.

    Its used in a sort of "thread-environment"

    When a new thread is created the Parent-ID gets value 0.
    When a new posting is a comment to a previous one the ParentID-value
    equals the ID-value for the parent-posting.

    Like this

    ID ParentID Indatatime
    1 0 03.01
    2 0 03.29
    3 0 06.10
    4 1 07.38
    5 0 11.15
    6 3 11.30
    7 1 11.59

    Now I want to pull them from the Access-DB and present them very
    logically with every ID with parentID = 0 followed by its respective
    comments - like this

    ID ParentID Indatatime
    1 0 03.01
    4 1 07.38
    7 1 11.59
    2 0 03.29
    3 0 06.10
    6 3 11.30
    5 0 11.15


    This line almost does it
    SQL = "SELECT * FROM MYTABLE ORDER BY ParentID DESC"

    but the postings with identical ParentID sometimes present themselves
    irrational. That is why I have added an Indatatime column - but I have
    failed in creating a solution that does the above.

    This for ex - doesnt do it - gives syntax error
    SQL = "SELECT * FROM MYTABLE ORDER BY CASE WHERE ParentId 0 THEN ID ELSE
    ParentID END, INDATATIME DESC"

    Good ideas somebody??


    Bob the ASP Builder

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Bob the ASP Builder Guest

  2. Similar Questions and Discussions

    1. Having Problems With SQL Statement[ACCESS DB]
      Hi, This is my SQL Procedure : IFF(21 in(SELECT PageID FROM TBL_Trafic WHERE PageID=21), (UPDATE TBL_Trafic SET Hits=Hits+1,...
    2. Trying to show content from Rss source in datagrid
      Hi! I'm trying to show content from an RSS source in a datagrid, it works fine if all my "properties" exist.. But if I have an RSS where there...
    3. Access 2k SQL Statement
      I am trying to get the SQL statement right for querying an Access 2k database I would like to obtain the first record of Event A and the last...
    4. access insert statement
      have you tried? was there an error? I'm not sure that Access has the "@@identity".... I'd suggest trying and posting the specific errors. --...
    5. pass sql where statement into access report
      I am trying to automate production of an Access report via ASP. I have almost got there apart from the fact that I want to send either an SQL...
  3. #2

    Default Re: Show Access DB-content with i.e. WHEN-statement??

    Bob,

    One of the solutions is to create the ID that contains all the parent keys,
    and also level info.

    e.g.

    ThreadID ParentID Level Message
    -------- --------- ----- -----------------------
    1 0. 1 First Message
    2 0.1. 2 Responding to "First Message"
    3 0.1.2. 3 Responsing to "Responding to First Message"
    4 0.1 2 Responding to "First Message"


    The parent ID is created by concatenating the parentID of the parent thread
    + the thread ID of the parent thread. This way, you don't have to traverse
    all the way up to the top to find out all the ancestors. Plus, you can do
    some neat things with a composite parent ID like Delete/Update all the
    threads below a given message.

    To show the first level threads, you can simply do

    SELECT * FROM MYTABLE WHERE ParentID='0.' ORDER BY ThreadID DESC

    To show, say second level threads under threadID 1, do

    SELECT * FROM MYTABLE WHERE ParentID='0.1.' ORDER BY ThreadID DESC

    To show all the threads under threadID 1, do

    SELECT * FROM MYTABLE WHERE ParentID LIKE '0.1.*' ORDER BY ThreadID DESC

    Hope that gives you some ideas how to implement your discussion group.

    --
    Manohar Kamath
    Editor, .netBooks
    [url]www.dotnetbooks.com[/url]


    "Bob the ASP Builder" <anonymous@devdex.com> wrote in message
    news:ujKknY41DHA.1184@TK2MSFTNGP10.phx.gbl...
    > I have a database with an autoincrement ID-column and a ParentID-column.
    >
    > Its used in a sort of "thread-environment"
    >
    > When a new thread is created the Parent-ID gets value 0.
    > When a new posting is a comment to a previous one the ParentID-value
    > equals the ID-value for the parent-posting.
    >
    > Like this
    >
    > ID ParentID Indatatime
    > 1 0 03.01
    > 2 0 03.29
    > 3 0 06.10
    > 4 1 07.38
    > 5 0 11.15
    > 6 3 11.30
    > 7 1 11.59
    >
    > Now I want to pull them from the Access-DB and present them very
    > logically with every ID with parentID = 0 followed by its respective
    > comments - like this
    >
    > ID ParentID Indatatime
    > 1 0 03.01
    > 4 1 07.38
    > 7 1 11.59
    > 2 0 03.29
    > 3 0 06.10
    > 6 3 11.30
    > 5 0 11.15
    >
    >
    > This line almost does it
    > SQL = "SELECT * FROM MYTABLE ORDER BY ParentID DESC"
    >
    > but the postings with identical ParentID sometimes present themselves
    > irrational. That is why I have added an Indatatime column - but I have
    > failed in creating a solution that does the above.
    >
    > This for ex - doesnt do it - gives syntax error
    > SQL = "SELECT * FROM MYTABLE ORDER BY CASE WHERE ParentId 0 THEN ID ELSE
    > ParentID END, INDATATIME DESC"
    >
    > Good ideas somebody??
    >
    >
    > Bob the ASP Builder
    >
    > *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    > Don't just participate in USENET...get rewarded for it!

    Manohar Kamath [MVP] Guest

  4. #3

    Default Re: Show Access DB-content with i.e. WHEN-statement??

    Manohar's suggestion is good, but it involves error-prone processing when
    putting the data in.
    An alternative design is called "nested sets", which would make getting this
    resultset possible with a single query. Here is a link:
    [url]http://www.intelligententerprise.com/001020/celko.shtml[/url]


    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  5. #4

    Default Re: Show Access DB-content with i.e. WHEN-statement??

    Well - Manohar !

    Your suggestions sounds exactly what I want - and I have really tried
    hard to implement this - and succeeded - but only to some degree.

    I cant get this bit of code to work - whatever I try

    SQL = "SELECT * FROM MYTABLE WHERE ParentID LIKE '0.*'"

    Eventhough there actually are inputs with the ParentID value 0.1.

    It DOES work if I set the value to ParentID = 0.1 (just for the check)
    but that of course is not practically useful

    Whats wrong with my code? Im lost

    Bob the ASP Builder

    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Bob the ASP Builder Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139