Convert PLSQL to TSQL

  • I am newbie to rewrite the PLSQL to TSQL. Please give some conversions for below code in PLSQL to TSQL??? Thanks in advance.

    ==================================================

    PROCEDURE SaveTestAs(P_ProgramID NUMBER,

    P_ProgramName VARCHAR2)

    IS

    L_TestId INTEGER := 0;

    CURSOR L_Program IS

    SELECT *

    FROM PROGRAMS

    WHERE PROGRAM_ID = P_ProgramID;

    BEGIN

    FOR R_Programs IN L_Program LOOP

    INSERT INTO PROGRAMS

    VALUES(PROGRAMID.NEXTVAL,

    P_ProgramName,

    R_Programs.Program_Description,

    SYSDATE,

    R_Programs.Created_By,

    '',

    R_Programs.Station_NO);

    END LOOP;

    END SaveTestAs;

  • There is no cut and dry conversion for PL-SQL to T-SQL. Oracle loves using cursors, or at least all PL-SQL developers that I have been exposed to have loved to use them, and SQL Server does not. So, you really need to know what you are hoping to accomplish and then write it out again using the best set based operations that you can get in SQL Server.

    You can look up "Create Procedure" in Books OnLine or go here - http://msdn.microsoft.com/en-us/library/ms187926(SQL.90).aspx . There are great examples in both places.

    Hope this helps and please post back with any questions / problems that come up.

    David

    @SQLTentmaker

    “He is no fool who gives what he cannot keep to gain that which he cannot lose” - Jim Elliot

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

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