Ayesha Fathima

Ayesha Fathima

  • NA
  • 184
  • 29.9k

Use alias column in CONCAT expression

Mar 4 2020 3:18 AM
Hi there,
 
I'm trying to use alias column  in concate expression but it is not allowing me to use directly,I have tried by using some solutions but ended up with some issues.
 
Can someone please suggest something on this.Here is my simple query.
 
  1. SELECT DISTINCT scm_desc,   
  2.                 CASE   
  3.                   WHEN email.subject NOT LIKE '%INC00%' THEN email.create_date   
  4.                   ELSE NULL   
  5.                 END AS orgdate,   
  6.                 CASE   
  7.                   WHEN tr_status = 'Closed' THEN   
  8.                   Concat(CONVERT(VARCHAR(5),   
  9.                          Datediff(s, orgdate,   
  10.                          tr_modified_on) / 86400)   
  11.                   , 'D',   
  12.                                '' + ':'   
  13.                                +   
  14.                   CONVERT(VARCHAR(5), Datediff(s,   
  15.                                orgdate,   
  16.                   tr_modified_on)%86400/3600), 'H''' +   
  17.                                                    ':'   
  18.                                                     +   
  19.                   CONVERT(VARCHAR(5), Datediff(s, orgdate,   
  20.                   tr_modified_on)%3600/60), 'M')   
  21.                   ELSE ''   
  22.                 END AS overdue   
  23. FROM   dbo.ims_transaction   
  24.        LEFT JOIN ims_mtr_sub_category   
  25.               ON ims_mtr_sub_category.scm_id = ims_transaction.tr_sub_category   
  26.        LEFT JOIN dbo.email   
  27.               ON email.incident_no = ims_transaction.tr_incident_no   
  28. WHERE  tr_status NOT IN'stu_CLS' )   
  29.