PDA

View Full Version : Loop in SQL



Tzarevna
09-10-2014, 09:25 PM
Hey. I have a question about looping in SQL. I want to convert some given logic into SQL language (I am new to SQL). I am wondering whether it is possible to put the loop inside a CASE WHEN statement ? If anyone knows please consult me on this :) The original logic i am working with is this:

"IF v1=1 AND v2<>333 READ EACH v3 OCCURRENCE UNTIL YOU LOCATE THE 1ST OCCURRENCE WHERE v4=2 AND v5<=v6 THEN MOVE v7 ELSE MOVE v8".

I start converting into SQL syntax: " CASE WHEN v1=1 AND v2<>333... " and then not sure how to proceed.

Bob Phillips
09-11-2014, 01:16 AM
You can do the IF with a WHERE clause, but what does MOVE v7 ELSE MOVE v8 mean? Why do you want the 1st occurrence?

Probably better to explain what you need to do rather than asking how to convert a logic statement.