[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 343
  • Last Modified:

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;
0
crishna1
Asked:
crishna1
  • 2
1 Solution
 
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
 
twoboatsCommented:
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

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now