Help in Stored Procedure using join

  • Hi ,

    I have two tables Company and company details

    Company has columns COmpanyID(PK), EntityId, LastupdatedBy, Lastupdateddate

    I have to populate date into Company details which has columns

    CompanyDetailsID(PK),

    CompanyId,

    ,SubSectorId

    ,StateId

    ,CountryId

    ,RegionId

    ,LastUpdatedBy

    ,LastUpdatedDate

    I am able to write and populate date into my company table using this stored procedure

    INSERT Db_Company.Company

    (

    EntityId

    ,CompanyName

    ,LastupdatedBy

    ,LastUpdatedDate

    )

    Select

    stg.entityid,stg.publishedname,user, dbo.fnDateMap(getDate())

    from stgRating as stg

    left join

    Db_Company.Company as c

    on stg.entityid = c.entityid

    where c.entityid is null

    group by stg.entityid,stg.publishedname

    (Here PublishedName is my Staging table column name which populates my date, so i used it above.)

    I am not able to figure out to use which join in my companydetails table...

    So i used them as foreign keys(In CompanyDetails), Which are primary keys for the tables Sector, Subsectors etc....

    Sector, Subsectors etc are other tables in the db...

  • 1. I would like recommend you to post such a question in T-SQL forum. People there are more happy for this kind of question.

    2. You need to provide information on other tables in your question.

    3. You cancCheck BOL for the meaning of LEFT/RIGHT JOIN.

Viewing 2 posts - 1 through 1 (of 1 total)

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