Jump to content
  • 0

SQL CASE SELECT statement with conditions


Ras2019
 Share

Question

Hi,

I am trying to get data from a table to a datapage calculated field based on conditions that are chosen in the data page.. I get to work without any CASE & WHEN conditions i.e. if I only have to SELECT from one column, but that only takes me halfway.

Caspio continue to give me the ..... Incorrect syntax near (.   and I have tried to rewrite many times.

I would appreciate it a lot if anyone can see what im doing wrong in below statement!

 

CASE

WHEN [@field:Agree]="NO" AND [@field:Term]="Disc1" 

THEN

SELECT Price FROM Products WHERE Model=target.[@field:Model] AND Color=target.[@field:Color] 

WHEN [@field:Agree]="YES" AND [@field:Term]="Disc1" 

THEN

SELECT PriceReb FROM Products WHERE Model=target.[@field:Model] AND Color=target.[@field:Color] 

END

 

Sincerely

Ras

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

Hi @Ras2019,

You should wrap your SQL query with brackets and also use "0/1" for checkbox field comparison.

So, your formula should look like this:

CASE

WHEN [@field:Agree]=0 AND [@field:Term]="Disc1" 

THEN

(SELECT Price FROM Products WHERE Model=target.[@field:Model] AND Color=target.[@field:Color]) 

WHEN [@field:Agree]=1 AND [@field:Term]="Disc1" 

THEN

(SELECT PriceReb FROM Products WHERE Model=target.[@field:Model] AND Color=target.[@field:Color]) 

END

Hope this helps.

Regards,

vitalikssssss

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...