SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


please help me convert this part into SQL Server.


please help me convert this part into SQL Server.

Author
Message
ekant_alone
ekant_alone
Mr or Mrs. 500
Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)Mr or Mrs. 500 (526 reputation)

Group: General Forum Members
Points: 526 Visits: 473
IF OUT_PAT_VISIT_ID_V = 'Collected' and NO_OUT_PAT_VISIT_ID_V = 'Collected' THEN
:NEW.PAT_VISIT_ID := 'Collected';
ELSIF OUT_PAT_VISIT_ID_V = 'Collected' THEN
:NEW.PAT_VISIT_ID := NO_OUT_PAT_VISIT_ID_V;
ELSIF NO_OUT_PAT_VISIT_ID_V = 'Collected' THEN
:NEW.PAT_VISIT_ID := OUT_PAT_VISIT_ID_V;
ELSE
IF OUT_PAT_VISIT_START_DTTM_V > NO_OUT_PAT_VISIT_START_DTTM_V THEN
:NEW.PAT_VISIT_ID := OUT_PAT_VISIT_ID_V;
ELSE
:NEW.PAT_VISIT_ID := NO_OUT_PAT_VISIT_ID_V;
END IF;
END IF;
END IF;
davoscollective
davoscollective
SSCommitted
SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)SSCommitted (1.7K reputation)

Group: General Forum Members
Points: 1691 Visits: 1008
It's hard to provide a translation without the rest of the code, and I don't believe blindly translating it for you would benefit you at all.

I can give you some clues though.
Those :parameters would be defined in the rest of the code you haven't supplied, probably as part of a stored procedure or a function.
IF-THEN-ELSE works almost the same in T-SQL. Read up on control-flow in T-SQL.

When you say convert to SQL Server, are you porting your database from Oracle to SQL server? If yes then you will need to define the stored procedure with input and output parameters. I suggest reading an intro to T-SQL stored procedures on MSDN. If you are familiar with PL/SQL then it will be very easy for you. If you're not then I suggest you are way out of your depth and asking for straight transliterations on a forum is a bad idea. Note I didn't say translation, because without context you can't translate any language into another language.
s.lakhanpal6776
s.lakhanpal6776
Grasshopper
Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)Grasshopper (11 reputation)

Group: General Forum Members
Points: 11 Visits: 43
use select case for this issue.
Ed Wagner
Ed Wagner
SSC Guru
SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)SSC Guru (50K reputation)

Group: General Forum Members
Points: 50171 Visits: 10844
From the syntax, I'm going to assume that this code is part of a trigger where you're referencing OLD AS OLD and NEW AS NEW and that it's a FOR EACH ROW. If this assumption is incorrect, you can completely ignore the rest of this post. It's been a while since I worked in Oracle.

The :NEW is a pseudo-row that refers to the row being inserted. SQL Server has the INSERTED keyword to refer to the same thing. Also, you're going to want to remove the THEN and END IF lines. Replace the ELSIF with ELSE IF statements. The last thing I see is to replace Oracle's := assignment syntax with a simple = instead.

BEGIN...END blocking is required if you have multiple statements being executed in a decision structure.


Tally Tables - Performance Personified
String Splitting with True Performance
Best practices on how to ask questions
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search