we have a very old database table that is used for discount codes.
Right now we have columns called discountValue & discountPercent
When a user creates a voucher code, if it is a value amount the value is stored in the value column, and if it is a percentage value this value is stored in the percentage column.
We are using MSSQL 2012 now and have just realised about this problem as it makes the UI look quite awkward.
Is there a way within SQL for MSSQLServer to query the database and alias a column in the output that detects if one of the columns is empty, it will use store the value in 1 column we can use to output to the user ?
I imagine this is kind of like a conditional statement... but im not sure how to write such a thing in MSSQL ?
thanks in advance
2 Answers 2
1 Comment
COALESCE
and ISNULL
is at MSDN Blogs [here](blogs.msdn.com/b/sqltips/archive/2008/06/26/… ).Use COALESCE()
function:
SELECT COALESCE(discountValue, discountPercent) as Discount
FROM Table
See Link here