sql - How to select different columns depending on values in a column -


so, have table columns staff, associate , matter type (which either set 'lit' or 'psd'.)

when type field = 'lit' need include staff field staff field in select statement. when type field set 'psd' need include associate field staff field in select statement.

i know can 2 separate queries, cannot figure out how combine 2 single query - there's easy answer, after not being able figure out while, i'm not coming answer.

ideas?

select     case when         [mattertype] = 'lit'             [staff]     else         [associate]     end [newstaff]     mytable; 

this uses inline case condition in select list.


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -