tags:

views:

38

answers:

1

Hi,

I am using SQL Query and below are the tables.

Organization

OrgID    Name        RAOGID   RAOID   SubGroupID   StatusID
1       Org RAOG1   1   NULL       NULL                2
2       Org RAO1         NULL    1     NULL      3
3       Org Sub Group1   NULL       NULL      1        1
4       Org RAOG2   2   NULL       NULL                2
5       Org RAO2         NULL    2     NULL      3
6       Org Sub Group2   NULL       NULL      2        2

RAOG

RAOGID  AccredID
1              2  
2              2  
3              2

RAO

RAOID   RAOGID
1         1
2         3
3         3

Sub Group

SubGroupID  RAOID
1            1
2            2
3            2

I have four tables as shown above, here is details of them, 1) Every RAOG, RAO and SUBGROUP are a organisation 2) RAOG can have many RAOs 3) RAO can have many SubGroups

I want to update my organisation table statusid, before updating I want to check if it is the RAOG type of oraganisation then it will update all the RAOs and SUBGROUPs under it and same with RAO it will update all the SUBGROUP under him it will not update it parent RAOG.And at last if it SUBGROUP type of organisation it will only update the subgroup not its parent records.

Thanks, Best Regards, Manoj

+1  A: 

This is best acheived by wrapping the checks and calls you want to make into a stored procedure that you can then execute within a transaction.

CREATE PROCEDURE [dbo].[MySprocOfDoom]

@param1    paramType,
    --...
AS
BEGIN
SET NOCOUNT ON;
    --SELECT statements here
END
butterchicken
Can you please write the code as I am not able to write sql code for it
MKS
Then perhaps you should not have been given a job where you need to write SQL
oxbow_lakes
dear I am asking the logic code for above problem, I know very well about the SQL syntax, I am bit confused how i can get the above results. We can use function or procedure. Please give me the actual sql code?
MKS
I don't think it is reasonable for me to give you the code to a problem you are (presumably) being paid to solve yourself - do you? If you can write a SPROC, and SELECT statements and IF statements, then you're 90% of the way there - the other 10% is effort!
butterchicken