SteveMott Posted February 11, 2023 Report Share Posted February 11, 2023 Hi I have an issue with writing the correct SQL syntax. Please see attached document. Any help really appreciated. Thanks Steve PharmAdvisor14.docx Quote Link to comment Share on other sites More sharing options...
0 NiceDuck Posted February 14, 2023 Report Share Posted February 14, 2023 What is the 'Select' before the 'Case' there for? Quote Link to comment Share on other sites More sharing options...
0 SteveMott Posted February 14, 2023 Author Report Share Posted February 14, 2023 Removed that SELECT, there in in error. Still no result showing. Updated document attached Thanks Steve PharmAdvisor14.docx Quote Link to comment Share on other sites More sharing options...
0 CoopperBackpack Posted February 15, 2023 Report Share Posted February 15, 2023 Hello @SteveMott, I don`t see the PRR field on the screenshots that your provided. I assume that this is some numeric field in the FullReactionIngredients table. If so, it looks like the syntax for converting the value is not correct. Please test this instead: CASE WHEN (SELECT COUNT(DrugReactionID) FROM FullReactionIngredients WHERE DrugReactionID = '[@calcfield:1]') = 1 THEN (SELECT CONVERT(VARCHAR, PRR) FROM FullReactionIngredients WHERE DrugReactionID = '[@calcfield:1]') ELSE 'No cases reported' END I think for the similar requests you may contact support team via tickets to get a quicker reply. Quote Link to comment Share on other sites More sharing options...
0 SteveMott Posted February 15, 2023 Author Report Share Posted February 15, 2023 Thanks @CoopperBackpack The calculation still goes to ELSE even when the conditions for the WHEN statement are true. I have the WHEN statement working correctly in other tables, so I am wondering what the preconditions for this to succeed need to be met. I shall take your advice and put in a ticket to support. I do appreciate your time. Thanks Steve Quote Link to comment Share on other sites More sharing options...
0 SteveMott Posted February 15, 2023 Author Report Share Posted February 15, 2023 Hi @CoopperBackpack Support got back to me with this code: CASEWHEN (SELECT COUNT(DrugReactionID) FROM FullReactionIngredients WHERE DrugReactionID = (target.[@field:IngredientID]+'[@ReactionID]')) = 1THEN (SELECT CONVERT(VARCHAR, (PRR)) FROM FullReactionIngredients WHERE DrugReactionID = (target.[@field:IngredientID]+'[@ReactionID]'))ELSE 'No cases reported'END Thanks and Cheers Steve Quote Link to comment Share on other sites More sharing options...
Question
SteveMott
Hi
I have an issue with writing the correct SQL syntax.
Please see attached document.
Any help really appreciated.
Thanks
Steve
PharmAdvisor14.docx
Link to comment
Share on other sites
5 answers to this question
Recommended Posts
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.