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!

Syntax help 1

Status
Not open for further replies.

LT2

MIS
May 24, 2006
232
US
SQL Svr 2000

I have the following select statement:
Code:
Select ac.Client, ag.Name, t.TxDate, v.PdAmt, p.Payor, v.CoPay, b.BillNum, b.AjDate, v.RPaySeq
From Payments v
  inner join AClient ac on v.ClientNum = ac.ClientNum
  inner join Provider ag on ac.ProvNum = ag.ProvNum
  left join FundingSource p on v.FSID = p.FSID
  inner join BDetail bd on v.BDID = bd.BDID
  left join Bill b on bd.BLID = b.BLID
  inner join Treat t on bd.TxID = t.TxID
Where bd.Status = 2 --Paid
  and b.Adjd = 1 --Adjudicated
  and ag.ProvNum = 111

I would like to incorporate into the select portion an additional field based upon the following criteria.

Code:
(IF v.PdAmt < 0
 Then 'Void'
  If v.RpaySeq = 99
  Then 'Reallocate'
  Else 'none' ) as 'AdjustType'

Can anyone offer some guidance?
 
try this:

Code:
Select ac.Client, ag.Name, t.TxDate, v.PdAmt, p.Payor, v.CoPay, b.BillNum, b.AjDate, v.RPaySeq[!],
       Case When v.PdAmt < 0 Then 'Void'
            When v.RpaySeq = 99 Then 'Reallocate'
            Else 'none' 
            End as 'AdjustType'[/!]
From Payments v
  inner join AClient ac on v.ClientNum = ac.ClientNum
  inner join Provider ag on ac.ProvNum = ag.ProvNum
  left join FundingSource p on v.FSID = p.FSID
  inner join BDetail bd on v.BDID = bd.BDID
  left join Bill b on bd.BLID = b.BLID
  inner join Treat t on bd.TxID = t.TxID
Where bd.Status = 2 --Paid
  and b.Adjd = 1 --Adjudicated
  and ag.ProvNum = 111

-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Excellent, Thanks George!

I tried CASE but obviously had something wrong.

Thank you for your prompt reply, it is greatly appreciated.

LT
 
You're welcome.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top