Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
tksnota
Post Patron
Post Patron

Error When Running The Code: Incorrect syntax near the keyword 'CASE'

Hi,

 

I need help on these codes because I'm getting the error as shown from the subject.  FYI. gbkmut.bdr_hfl are numeric values

 


CASE WHEN gbkmut.transtype IN ('N','C','P','F')
AND gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0
OR gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0
THEN gbkmut.bdr_hfl
ELSE NULL
END AS Debit,

CASE WHEN gbkmut.transtype IN ('N','C','P','F')
AND gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0
OR gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0
THEN NULL
ELSE -gbkmut.bdr_hfl
END AS Credit

 

tksnota_0-1735827262631.png

 

1 ACCEPTED SOLUTION
Smalfly
Responsive Resident
Responsive Resident

Good to hear that your problem is solved!

Just add a comma behind the * and the quety will give you all the columns in the table.

View solution in original post

6 REPLIES 6
Smalfly
Responsive Resident
Responsive Resident

Hi @tksnota ,

 

for your printscreen I don't see the whole SQL query but it needs to be a query that runs on its own in your SQL evironment. So it will be something like select columnA, columnB from TableX.

 

If your query looks correct, try running it in your SQL environment. That might give you a more meaningful error.

 

Good luck!

I still got the same error...

 

SELECT gbkmut.reknr, gbkmut.bdr_hfl
CASE WHEN gbkmut.transtype IN ('N','C','P','F')
AND gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0
OR gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0
THEN gbkmut.bdr_hfl
ELSE NULL
END AS Debit,

SELECT gbkmut.reknr, gbkmut.bdr_hfl
CASE WHEN gbkmut.transtype IN ('N','C','P','F')
AND gbkmut.transsubtype NOT IN ('R','S')
AND gbkmut.bdr_hfl >= 0
OR gbkmut.transsubtype IN ('R','S')
AND gbkmut.bdr_hfl < 0
THEN NULL
ELSE -gbkmut.bdr_hfl
END AS Credit

Smalfly
Responsive Resident
Responsive Resident

Try this:

 

SELECT gbkmut.reknr, gbkmut.bdr_hfl,
CASE WHEN gbkmut.transtype IN ('N','C','P','F') AND gbkmut.transsubtype NOT IN ('R','S') AND gbkmut.bdr_hfl >= 0 OR gbkmut.transsubtype IN ('R','S') AND gbkmut.bdr_hfl < 0
THEN gbkmut.bdr_hfl
ELSE NULL END AS Debit,
CASE WHEN gbkmut.transtype IN ('N','C','P','F') AND gbkmut.transsubtype NOT IN ('R','S') AND gbkmut.bdr_hfl >= 0 OR gbkmut.transsubtype IN ('R','S') AND gbkmut.bdr_hfl < 0
THEN NULL ELSE -gbkmut.bdr_hfl END AS Credit
FROM gbkmut

 

What I did:

 

* I added a comma behind gbkmut.bdr_hfl

* I removed your second select statement

* I added a from statement in which I assumed gbkmut is your table name

Hi,

 

It worked!

 

Is it possible to get the whole fields of gbkmut instead of the couple?

 

I used SELECT * but got the same error as shown

 

tksnota_0-1735835378546.png

 

Smalfly
Responsive Resident
Responsive Resident

Good to hear that your problem is solved!

Just add a comma behind the * and the quety will give you all the columns in the table.

tksnota
Post Patron
Post Patron

"601"{[Schema="dbo",Item="gbkmut"]}[Data] - Forgot to add this one

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

Find out what's new and trending in the Fabric community.

Top Solution Authors
Top Kudoed Authors