Results 1 to 4 of 4
  1. #1
    Join Date
    Sep 2009
    Posts
    5

    Unanswered: How to convert oracle SQL code to SQL server code

    Hi all,

    i kinda new with SQLserver2008..currently i have a code that generates some function and its work on oracle SQL. What i should do now is how to convert the code to MSSQL server code. Kindly need all of guru's out there to guide me on this.

    Here are the codes



    create or replace
    PROCEDURE A (tbl_name varchar2 default ' ',
    l_name varchar2 default ' ',
    f_name varchar2 default ' ',
    full_name varchar2 default ' ',
    ssn varchar2 default ' ',
    gender_col varchar2 default ' ',
    employee_id varchar2 default ' ') IS


    v_tbl varchar2(30) := tbl_name;
    v_lname varchar2(30) := l_name;
    v_fname varchar2(30) := f_name;
    v_fullname varchar2(30) := full_name;
    v_ssn varchar2(30) := ssn;
    v_gender varchar2(30) := gender_col;
    v_empid varchar2(30) := employee_id;
    v_num number(10) := 1;
    v_row integer;


    proc_id varchar2(30) := 'Change process';

    V_ERR_CD VARCHAR2(40);
    V_ERR_NAME VARCHAR2(100);

    BEGIN





    if (v_tbl = ' ') then

    dbms_output.put_line('Must put table name');
    else

    EXECUTE IMMEDIATE 'SELECT COUNT(*) FROM '||v_tbl INTO v_row;


    if (v_lname <> ' ') and (v_empid <> ' ') then

    execute immediate '
    update
    (select a.'||v_lname||' a_lname, a.'||v_empid||' a_empid, b.last_name b_lname, b.employee_id b_emplid
    from '||v_tbl||' a, CHANGED b
    where b.emplid = a.'||v_empid||')
    set a_lname= upper(b_lname) ';

    end if;

    --------------------------------------------------------------------------------------------------------------------------------
    if (v_fname <> ' ') and (v_empid <> ' ') and (v_gender <> ' ')then

    execute immediate '
    update
    (select a.'||v_fname||' a_fname, a.'||v_empid||' a_empid, a.'||v_gender||' a_gender,
    b.male_first_name b_mfname, b.female_first_name b_ffname, b.unisex_name b_uname, b.employee_id b_emplid
    from '||v_tbl||' a, CHANGED b
    where b.emplid = a.'||v_empid||')
    set a_fname= decode(a_gender,''U'', upper(b_uname),(decode(a_gender,''F'', upper(b_ffname), upper(b_mfname))))';

    end if;
    -----------------------------------------------------------------------------------------------------------------------------------

    if (v_fullname <> ' ') and (v_empid <> ' ') and (v_gender <> ' ')then

    execute immediate '
    update
    (select a.'||v_fullname||' a_full, a.'||v_empid||' a_empid, a.'||v_gender||' a_gender,
    b.male_first_name b_mfname, b.female_first_name b_ffname, b.unisex_name b_uname, b.last_name b_lname, b.employee_id b_emplid
    from '||v_tbl||' a, CHANGED b
    where b.emplid = a.'||v_empid||')
    set a_full=
    concat( upper(b_lname) ||'' , '',
    (decode(a_gender,''U'', upper(b_uname),(decode(a_gender,''F'', upper(b_ffname), upper(b_mfname))))))';

    end if;
    ---------------------------------------------------------------------------------------------------------------------------------------


    if (v_lname <> ' ') and (v_empid <> ' ') then
    dbms_output.put_line(v_row||' '||v_lname||' from table '||v_tbl||' have been change');
    end if;

    if (v_fname <> ' ') and (v_empid <> ' ') and (v_gender <> ' ') then
    dbms_output.put_line(v_row||' '||v_fname||' from table '||v_tbl||' have been change');
    end if;

    if (v_fullname <> ' ') and (v_empid <> ' ') and (v_gender <> ' ') then
    dbms_output.put_line(v_row||' '||v_fullname||' from table '||v_tbl||' have been change');
    end if;

    if (v_ssn <> ' ') then
    execute immediate '
    update '||v_tbl||' set
    '||v_ssn||'= translate('||v_ssn||',''0123456789'',''5678901234' ')
    where rownum <= '||v_row||'';

    dbms_output.put_line(v_row||' '||v_ssn||' from table '||v_tbl||' have been change');
    end if;

    end if;

    EXCEPTION

    WHEN OTHERS THEN
    dbms_output.put_line('Error Encountered ' || substr(sqlerrm,1,200));
    V_ERR_CD := SQLCODE;
    V_ERR_NAME :=SQLERRM;
    IF V_ERR_CD = 'ORA-01401' THEN
    dbms_output.put_line('Procedure Compiled with Errors');
    END IF;


    END A;

    Basically it loads Procedure A which will take some input from user...then it will change data from temporary table CHANGED to input table data

  2. #2
    Join Date
    Jan 2007
    Location
    UK
    Posts
    11,434
    Provided Answers: 10
    Aww come on, you can at least give it a try!
    George
    Home | Blog

  3. #3
    Join Date
    Nov 2004
    Location
    on the wrong server
    Posts
    8,835
    Provided Answers: 6
    I would star by learning t-sql. There are many ways to do that. SQL Server Books Online (installed with SQL server) is a wonderful resource. There are also online tutorials and books galore. And of course if you have any specific problems you can always come back here for help.

    Sniped.
    “If one brings so much courage to this world the world has to kill them or break them, so of course it kills them. The world breaks every one and afterward many are strong at the broken places. But those that will not break it kills. It kills the very good and the very gentle and the very brave impartially. If you are none of these you can be sure it will kill you too but there will be no special hurry.” Earnest Hemingway, A Farewell To Arms.

  4. #4
    Join Date
    Nov 2002
    Location
    Jersey
    Posts
    10,322
    Actually, I don't think you would want to convert this in the first place...

    It's not very good to begin with

    What is it that you actually want to have happen?
    Brett
    8-)

    It's a Great Day for America everybody!

    dbforums Yak CorralRadio 'Rita
    dbForums Member List
    I'm Good Once as I ever was

    The physical order of data in a database has no meaning.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •