select case when id=1 then case when name='' then cols1 else '' end else '' end colfrom table where cols2 = case when id=1 then case when name='' then cols1 else '' end else '' end