Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2008
    Posts
    16

    Unanswered: How to solve this?

    Hi ,
    I have a table named Site whose columns are

    id typId NOT NULL,
    code varchar(4) NOT NULL,
    nom typLib64 NOT NULL,
    telephone typTelephone NULL,
    fax typTelephone NULL,
    eMail typEmail NULL,
    siteIdRattachement typId NULL,
    niveauOrganisationnelCode typCodeObjRef NOT NULL

    ADD CONSTRAINT FK_SITE_RATTACHEMENT
    FOREIGN KEY (siteIdRattachement)
    REFERENCES dbo.Site (id)

    I have to prepare a query so that for a given ID it gives the highest level site

    Eg
    Id siteIdRattachement

    1 2
    2 3
    3 4
    4 Null
    5 3
    7 6
    6 9

    IF I input 1 then I should get 4

    Similarly If I enter 5 I should get 4
    Similarly If I enter 7 I should get 9

    I have implemented this using a while loop and if exists condition
    but i have to do this in one query :-(

    Regards,
    71189131

  2. #2
    Join Date
    Jan 2008
    Posts
    16
    can this be done?

  3. #3
    Join Date
    May 2005
    Location
    South Africa
    Posts
    1,365
    Provided Answers: 1
    I do not understand

Posting Permissions

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