Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using a conditional statement in a select

Status
Not open for further replies.

ghbeers

Programmer
Jul 17, 2014
76
US
I am inserting data into a temp table and want a conditional statement on one item that will insert the code description if found in the code table or want the code if not found. All of the joins not shown are returning the correct values, so they are not a factor in my issue. My insert select statement looks something like...

select DISTINCT P.POSITION_ID,
PPI.HRPER_ID,
PS.PERSTAT_PRIMARY_POS_ID,
P.POS_TITLE,
P.POS_START_DATE,
P.POS_END_DATE,
DIV.DIV_DESC,
DEP.DEPTS_DESC,

<the following is the logic I want but I can't get sql to like no matter what I try>

if (V1.VAL_EXTERNAL_REPRESENTATION is NULL) then
P.POS_CLASS;
else
V1.VAL_EXTERNAL_REPRESENTATION;
end if


V2.VAL_EXTERNAL_REPRESENTATION,
PPF.POSPAY_FNDG_GL_NO,
PPF.POSPAY_FNDG_PCT,
PPF.POSPAY_FNDG_PROJ_ID,
 
Code:
select DISTINCT P.POSITION_ID,
       PPI.HRPER_ID,
       PS.PERSTAT_PRIMARY_POS_ID,
       P.POS_TITLE,
       P.POS_START_DATE,
       P.POS_END_DATE,
       DIV.DIV_DESC,
        DEP.DEPTS_DESC,
        COALESCE(V1.VAL_EXTERNAL_REPRESENTATION, P.POS_CLASS),
....

Borislav Borissov
VFP9 SP2, SQL Server
 
Thank you so much, forgot about the COALESCE statement. That did it for me.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top