title: Single conditional select query in SQL
body: <p>I have the following table say filenames.</p>
  
  <pre><code>filename   flag
  fileA       1
  fileB       0
  fileC       0
  fileD       1
  fileA       1
  </code></pre>
  
  <p>I want all distinct filenames from this table AND
  If the flag is 1 for any file name, i want that file name to be replaced with 4 file names as FilaA_part_1, FilaA_part_2, FilaA_part_3, FilaA_part_4.</p>
  
  <p>output should be </p>
  
  <pre><code>FilaA_part_1
  FilaA_part_2
  FilaA_part_3
  FilaA_part_4
  fileB      
  fileC
  FilaD_part_1
  FilaD_part_2
  FilaD_part_3
  FilaD_part_4     
  </code></pre>
  
  <p>I am able to achieve this with temp table. I want to know if it is possible with single select query.</p>
  
  <p>I could get as far as</p>
  
  <pre><code>SELECT DISTINCT CASE WHEN FLAG=1 THEN FILENAME + '_part_1' 
  ELSE FILENAME END
  FROM FILENAMES
  </code></pre>