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

Popular posts from this blog

How to logout from a login page in asp.net -

Stack level too deep error after upgrade to rails 3.2 and ruby 1.9.3 -