sql server - Writing CASE Statement in SQL -
i have requirement display 2 columns in report,whose values determined using same input expression following:
select case when id>10 'aaaa' else 'bbbb' end 'firstcolumn', case when id>10 'bbbb' else 'dddd' end 'secondcolumn'
can construct expression without repeating input expression twice same?
you need repeat case statment each field while condition might same teh results differnt. other alternative use union statement whenre first select takes records id<=10 , other 1 id>10. can bea viable alternative littel hareder maintain, if performance enough, iwoudl stick repeating teh case condition.
Comments
Post a Comment