CASE Statement

%3CLINGO-SUB%20id%3D%22lingo-sub-736229%22%20slang%3D%22en-US%22%3ECASE%20Statement%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-736229%22%20slang%3D%22en-US%22%3E%3CP%3EI%20am%20a%20SQL%20novice.%20Our%20SQL%20expert%20is%20unavailable%20and%20I%20need%20to%20make%20some%20small%20changes%20to%20a%20stored%20procedure%2C%20any%20help%20would%20be%20appreciated.%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3ESo%20I%20have%20a%20stored%20procedure%20that%20pulls%20the%20data%20into%20an%20Excel%20spreadsheet.%20Here%20is%20what%20the%20output%20looks%20like%3A%3C%2FP%3E%3CP%3E%3CIMG%20src%3D%22https%3A%2F%2Fi.gyazo.com%2F3e5a4684879d1717058fa35de7db404f.png%22%20border%3D%220%22%20width%3D%22571%22%20height%3D%22112%22%20%2F%3E%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3EWhat%20I%20am%20trying%20to%20accomplish%20is%20when%20the%20%25%20is%200%20or%20the%20Incentive%20is%20blank%2C%20I%20want%20the%20Pay%20column%20to%20be%20a%200.%20Attached%20is%20the%20query%20for%20the%20stored%20procedure.%20At%20the%20end%20of%20the%20code%2C%20you%20will%20see%20the%20CASE%20statements%20for%20the%20columns.%20Thank%20you!!%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-SUB%20id%3D%22lingo-sub-787299%22%20slang%3D%22en-US%22%3ERe%3A%20CASE%20Statement%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-787299%22%20slang%3D%22en-US%22%3E%3CP%3E%3CA%20href%3D%22https%3A%2F%2Ftechcommunity.microsoft.com%2Ft5%2Fuser%2Fviewprofilepage%2Fuser-id%2F238560%22%20target%3D%22_blank%22%3E%40Tim%20Hunter%3C%2FA%3E%26nbsp%3B%3C%2FP%3E%3CP%3EYou%20can%20use%20a%20case%20statement%20in%20Pay%20column%20something%20like%20that%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CPRE%20class%3D%22lia-code-sample%20language-cpp%22%3E%3CCODE%3Ecase%20when%20(se%20%26lt%3B1%20or%20ty%20%3D3%20or%20yr%20%3D0%20or%20st%20%3D'OUT')%0Athen%200%20else%20py%0Aend%3C%2FCODE%3E%3C%2FPRE%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3CP%3E%26nbsp%3B%3C%2FP%3E%3C%2FLINGO-BODY%3E
Highlighted
Regular Contributor

I am a SQL novice. Our SQL expert is unavailable and I need to make some small changes to a stored procedure, any help would be appreciated.

 

So I have a stored procedure that pulls the data into an Excel spreadsheet. Here is what the output looks like:

 

What I am trying to accomplish is when the % is 0 or the Incentive is blank, I want the Pay column to be a 0. Attached is the query for the stored procedure. At the end of the code, you will see the CASE statements for the columns. Thank you!!

 

 

 

 

1 Reply
Highlighted

@Tim Hunter 

You can use a case statement in Pay column something like that

 

 

case when (se <1 or ty =3 or yr =0 or st ='OUT')
then 0 else py
end