Reputation: 345
Is it possible to use this sql query?
select ([discount_type]='Percent') ? [Percent]+'%' : [Amount]+'RS' as [Discount] from [admin].[discount] where [discount_id]=2
Upvotes: 1
Views: 54
Reputation: 129802
You can make a CASE
(which is pretty much like a switch
in many other languages)
SELECT
CASE [discount_type]
WHEN 'Percent' THEN [Percent] + '%'
ELSE [Amount] + 'RS' END as [Discount]
FROM [admin].[discount]
WHERE [discount_id] = 2
Note that the rest of the query uses your code as is, i.e. assuming that Percent
can be concatenated with a string without prior conversion.
Upvotes: 3