Another Stored Procedure

  • Trying to do the following for general purposes, here's the specifics:

     

    Two Tables: (Person, Address)

    Person: Person_ID, First_NM and Last_NM

    Address: Address_ID, Person_Id (Unique identifier) and Address_Text

     

    Two Parameters: (@First_NM, @Last_NM)

     

    Need to return the address text by querying a person _id linked to the the person name.

     

     

    TIA

  • Can't work, names are repeatable so you might have 2 John Smith>>returning 2 ids.

    In what context would you want to do that?

  • Just an example that I need to put together, but not in actual development, here is what I have so far.

     

    CREATE PROCEDURE sp_findaddress

            @LAST_NM varchar(25),

            @FIRST_NM varchar(25),

     

    AS

    SELECT @LAST_NAME, @FIRST_NM FROM PERSON

    WHERE @LAST_NM, @FIRST_NM=PERSON_ID

     

    I'm not sure how to go about querying the ADDRESS table from here??

  • Seems too much like an homework question...

    This is just a simple inner join, there's no way a programmer can't figure this one out.

  • Anyone else?

  • Thanks RGR,

     

    Here's what I have now:

    CREATE PROCEDURE sp_findaddress

            @LAST_NM varchar(25),

            @FIRST_NM varchar(25),

     

    AS

    SELECT PERSON.LAST_NM AND FIRST_NM, ADDRESS.PERSON_ID

    FROM PERSON, ADDRESS

    WHERE PERSON.EMPLOYEE_ID=ADDRESS.ADDR.TEXT

  • This is probably closer:

     

    SELECT PERSON.LAST_NM, PERSON.FIRST_NM, ADDRESS.ADDR_TEXT

    FROM PERSON, ADDRESS

    WHERE PERSON.EMPLOYEE_ID=ADDRESS.PERSON_ID


    And then again, I might be wrong ...
    David Webb

  • SELECT PERSON.LAST_NM, FIRST_NM, ADDRESS.Text

    FROM PERSON INNER JOIN ADDRESS

    ON PERSON.EMPLOYEE_ID=ADDRESS.EMPLOYEE_ID

    where PERSON.LAST_NM = @LAST_NM AND FIRST_NM = @FIRST_NM

  • hehehe...definitely looks like a homework question. You'll have to buy all these okes a beer if you pass Sasha.

  • haha, unfortunately didn't pass, but give's me a better understanding of how these things work.

Viewing 11 posts - 1 through 10 (of 10 total)

You must be logged in to reply to this topic. Login to reply