Covert Oracle querry to SQL Server

Dear experts, i need to convert the following , Oracle into SQL Server

CURSOR CBO IS
        SELECT BSI
        FROM PSIS
        WHERE REL = 1
        AND CBSB = 1;

CURSOR C_BS IS
        SELECT FD, SMO, EMO
        FROM PST_BS
        WHERE BSI = V_BSI_OLD;

IF to_number(V_G) = 1 THEN
                           CURSOR_NAME := DBMS_SQL.OPEN_CURSOR;
                            DBMS_SQL.PARSE(CURSOR_NAME,'truncate table pcon',DBMS_SQL.NATIVE);
                            Ret:= DBMS_SQL.EXECUTE(CURSOR_NAME);
              END IF;
crishna1Asked:
Who is Participating?
 
twoboatsConnect With a Mentor Commented:
if isnumeric(V_G)
begin
       open <cursorname>
end

Now, not a 100% sure what the PLSQL is doing in the if block (been a while since doing any PLSQL, and never use cursors on principle)....

But it looks like it's using a cursor to truncate a table??? In which case, in sql, you'd just use

TRUNCATE TABLE <table name>

0
 
twoboatsCommented:
declare CURSOR CBO for
        SELECT BSI
        FROM PSIS
        WHERE REL = 1
        AND CBSB = 1

declare CURSOR C_BS for
       SELECT FD, SMO, EMO
        FROM PST_BS
        WHERE BSI = @V_BSI_OLD

There after you just open the whichever cursor you need

eg

open CBO


0
 
dportasCommented:
Could you explain to what end you are doing this? Apparently you want to execute blocks of code dynamically in your database. Don't assume that the method you used in Oracle will also make sense in SQL Server.
0
 
crishna1Author Commented:
two boats, what about
IF to_number(V_G) = 1 THEN
                           CURSOR_NAME := DBMS_SQL.OPEN_CURSOR;
                            DBMS_SQL.PARSE(CURSOR_NAME,'truncate table pcon',DBMS_SQL.NATIVE);
                            Ret:= DBMS_SQL.EXECUTE(CURSOR_NAME);
              END IF;

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.