sql oracle code to T-sql for sql server

  • DECLARE

    nId NUMBER;

    BEGIN

    INSERT INTO TABLE A (

    name,

    age

    ) VALUES (

    'X',

    12

    ) RETURNING

    ID

    INTO nId;

    INSERT INTO TABLE B (

    id,

    address,

    marital status

    ) VALUES (

    nId,

    'at home',

    'married'

    );

    END;

    Can anyone please convert the above code in sql to T-sql please . I hardly know T-sql.Thanks

  • hi,

    try this way,

    --------

    DECLARE @NIDTBL TABLE(NID INT);

    DECLARE @NID INT;

    BEGIN

    INSERT A (

    NAME,

    AGE

    )OUTPUT INSERTED.ID INTO @NIDTBL VALUES (

    'X',

    12

    );

    SELECT @NID= NID FROM @NIDTBL;

    --SELECT @NID

    INSERT INTO TABLE B (

    ID,

    ADDRESS,

    [MARITAL STATUS],

    ) VALUES (

    @NID,

    'AT HOME',

    'MARRIED',

    ) ;

    END;

    Tharindu Dhaneenja.
    MCTS,MCITP(SQL Server),OCA(Oracle)
    http://www.databaseusergroup.com

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

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