Home » Asp.netRSS

need of Ascending order based on the Date and month.

Hi friends,


query.Append("SELECT Name, Sex, Marital_Status, Dob, Anniversary, Mobile, Email FROM Client WHERE ");

            if (startDate > new DateTime() && endDate > new DateTime())
            {
              
                query.Append("(DATEADD(YEAR,DATEDIFF(YEAR, DOB,'" + startDate + "'),DOB) BETWEEN '" + startDate + "'AND'" + endDate + "' OR DATEADD(YEAR,DATEDIFF(YEAR, ANNIVERSARY,'" + startDate + "'),ANNIVERSARY) BETWEEN '" + startDate + "'AND'" + endDate + "') AND ");
	
            }
           if (!string.IsNullOrEmpty(maritalStatus) && !string.Equals("All", maritalStatus))
            {
                query.Append(" Marital_Status = '" + maritalStatus + "'");
            }

            string resultQuery = query.ToString();
            if (resultQuery.Trim().EndsWith("AND", StringComparison.OrdinalIgnoreCase))
            {
                int lastIndex = resultQuery.LastIndexOf("AND");
                resultQuery = resultQuery.Remove(lastIndex, 3);
            }

            if (resultQuery.Trim().EndsWith("WHERE"))
            {
                int lastIndex = resultQuery.LastIndexOf("WHERE");
                resultQuery = resultQuery.Remove(lastIndex, 5);
            }

            return resultQuery.Trim();        
        }


I have used above code, This code working properly, but It  shows randomly,  
I need, 
The Data should have to display in ascending order based on the Date and month. 





 

2 Answers Found

 
 

Answer 2

 In the end,before return
append order  by clause.

Else explain with sample data that your query  return and you want sort on which colmn.

 
 
 

<< Previous      Next >>


Microsoft   |   Windows   |   Visual Studio   |   Follow us on Twitter