title: order by date field when datatype is nvarchar
body: <p>With one of the answers on stack I have used following query:</p>
  
  <pre><code>select 
    AVG(CASE WHEN Buy_sell = 1 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' and Sauda_Date between convert(datetime,'" + dtpForDate.Value.Date.ToString("dd/MM/yyyy") + "') and convert(datetime,'" + dtpToDate.Value.Date.ToString("dd/MM/yyyy") + "') THEN Market_Rate ELSE 0 END) AS AVGBuyRate , 
    AVG(CASE WHEN Buy_sell = 2 THEN Market_Rate ELSE 0 END) AS AVGSellRate,
    CONVERT(VARCHAR(11),sauda_date) AS sauda_date,  
    SUM(CASE WHEN Buy_sell = 1 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' and Sauda_Date between convert(datetime,'" + dtpForDate.Value.Date.ToString("dd/MM/yyyy") + "') and convert(datetime,'" + dtpToDate.Value.Date.ToString("dd/MM/yyyy") + "') THEN Trade_Qty ELSE 0 END) AS BuyQty,
    SUM(CASE WHEN Buy_sell = 2 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' and Sauda_Date between convert(datetime,'" + dtpForDate.Value.Date.ToString("dd/MM/yyyy") + "') and convert(datetime,'" + dtpToDate.Value.Date.ToString("dd/MM/yyyy") + "') THEN Trade_Qty ELSE 0 END) AS SellQty ,     
    SUM(CASE WHEN Buy_sell = 1 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' THEN Trade_Qty ELSE 0 END) -SUM(CASE WHEN Buy_sell = 2 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' THEN Trade_Qty ELSE 0 END) AS CarryForword 
  from tradefile 
  where scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "'
    and INST_TYPE LIKE 'FUT%' 
  group by CONVERT(VARCHAR(11),sauda_date) order by CONVERT(VARCHAR(11),sauda_date) desc
  </code></pre>
  
  <p>This query gives me output below:</p>
  
  <p><img src="https://i.stack.imgur.com/nMuB3.png" alt="enter image description here"></p>
  
  <p>In this if we look at sauda_date column, after 28 Feb 2013 it is ordering it by 22 Mar 2013 , then 21 Mar 2013 then 20 Mar 2013 , etc.</p>
  
  <p>But it should be 28 Feb 2013 , 1 Mar 2013 , 2 Mar 2013 .... , 20 Mar 2013 , 21 Mar 2013 , 22 Mar 2013.</p>
  
  <p>What changes I should make in query?</p>
  
  <p><strong>Note:</strong> sauda_date is of nvarchar type</p>
  
  <p><strong>NEW QUERY:</strong></p>
  
  <pre><code>select AVG(CASE WHEN Buy_sell = 1 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' and Sauda_Date between convert(datetime,'" + dtpForDate.Value.Date.ToString("dd/MM/yyyy") + "') and convert(datetime,'" + dtpToDate.Value.Date.ToString("dd/MM/yyyy") + "') THEN Market_Rate ELSE 0 END) AS AVGBuyRate , AVG(CASE WHEN Buy_sell = 2 THEN Market_Rate ELSE 0 END) AS AVGSellRate,  CONVERT(VARCHAR, CONVERT(DATETIME, sauda_date, 106), 106) as Sauda_Date,SUM(CASE WHEN Buy_sell = 1 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' and Sauda_Date between convert(datetime,'" + dtpForDate.Value.Date.ToString("dd/MM/yyyy") + "') and convert(datetime,'" + dtpToDate.Value.Date.ToString("dd/MM/yyyy") + "') THEN Trade_Qty ELSE 0 END) AS BuyQty,SUM(CASE WHEN Buy_sell = 2 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' and Sauda_Date between convert(datetime,'" + dtpForDate.Value.Date.ToString("dd/MM/yyyy") + "',106) and convert(datetime,'" + dtpToDate.Value.Date.ToString("dd/MM/yyyy") + "',106) THEN Trade_Qty ELSE 0 END) AS SellQty ,     SUM(CASE WHEN Buy_sell = 1 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' THEN Trade_Qty ELSE 0 END) -SUM(CASE WHEN Buy_sell = 2 and scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' THEN Trade_Qty ELSE 0 END) AS CarryForword from tradefile where scrip_code='" + ds.Tables[0].Rows[i][2].ToString() + "' and INST_TYPE LIKE 'FUT%' group by convert(datetime,sauda_date,106) order by convert(datetime,sauda_date,106) desc
  </code></pre>