Hi everyone,
I’m new to SQL.
I want to make a field that displays “-number” for TranTypes that are deducted from stock. When I first put only “STK-MTL” it worked fine. However, when adding “STK-CUS”, the following error message appears.
Please help on this issue. thank you.
Try changing:
PartTran.TranType = 'STK-MTL' or "STK-CUS"
to
PartTran.TranType IN ('STK-MTL', 'STK-CUS')
You could also do:
PartTran.TranType = 'STK-MTL' or PartTran.TranType = 'STK-CUS'
1 Like
case when PartTran.TranType in (‘STK-MTL’,‘STK-CUS’) then ‘-’ + convert(varchar, PartTran.TranQty)
else
convert(varchar, PartTran.TranQty)
end
Thank you so much. This issue has been resolved well.
I have one more question.
The above SQL was just how to make (-). What I originally intended is that (+) is displayed as (-), and (-) is displayed as (+).
how do i make this one?
You need some form of validation to check if your query is a positive transaction or a negative transaction.
Then you can do something along the lines of:
case
when (condition) then ('-' + CONVERT(varchar, PartTranTranQty))
else ('+' + CONVERT(varchar, PartTranTranQty))
end