• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: Changing query based on record value

Resolved: Changing query based on record value

0
By Isaac Tonny on 17/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

So I have this table to see usage report, Let’s say column A B C D E F
if column F has a particular value I want to A + B + C = E else I wanted A + B + C + D = E
My brain can’t handle the logic to be it in SQL query Do I need to use IF ELSE or DECLARE or CAST or idk

Answer:

Here is a possible way to do this; anyway I’d suggest to have a look to the SELECT CASE documentation since it’s not that complicated (I assumed you’re using sql server):
Edit: as suggested by @JonasMetzler, an ELSE would also do the job:
And since there seem to be just 2 options for F value to evaluate (‘being a certain value’ and ‘not being it’), we could also use an IIF statement:
and in the three examples, you could extract the A + B + C part since they are always added:

If you have better answer, please add a comment about this, thank you!

sql
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: Table data is coming as empty in React

02/04/2023

Resolved: In a Pinescript v5 Strategy why is my bool not working?

02/04/2023

Resolved: net::ERR_HTTP2_PROTOCOL_ERROR by http get request angular 15.2

02/04/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.