Home Forums SQL Server 7,2000 T-SQL SQL help on selecting records based on content and their neighbors content RE: SQL help on selecting records based on content and their neighbors content

  • Rob, your join is not considering the page number. you should probably include the page in the join.

    Michele, your final query pulls all the records of the matching page.. but Gary only needs the page with the sequence.

    My solution is :

    Select W.* from #wordmetadata  W

    Join (

    Select w1.page,w1.wsequence as seq1,w2.wsequence as seq2,w3.wsequence as seq3

    From

    #wordmetadata w1 inner join #wordmetadata w2

    on w1.page=w2.page and w2.wsequence<=w1.wsequence+1

    inner join #wordmetadata w3

    on w1.page=w3.page and w3.wsequence<=w1.wsequence+2

    Where

    w3.wsequence-w2.wsequence = 1 and

    w2.wsequence-w1.wsequence = 1 and

    w1.word='certificate' and w2.word='of' and w3.word='liability'

    ) as X

    ON

    W.page = x.page and (w.wsequence = seq1 OR  w.wsequence = seq2 OR w.wsequence = seq3)

     

     


    Kindest Regards,

    Hari