Sign In| Join
Get Help:Ask a Question in our Forums|Report a Bug|More Help Resources
Last post Oct 07, 2010 11:42 AM by KumarHarsh
Member
91 Points
90 Posts
Oct 07, 2010 11:22 AM|LINK
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(); }
All-Star
112229 Points
18266 Posts
Moderator
Oct 07, 2010 11:34 AM|LINK
Add an ORDER BY clause.
Refer: http://msdn.microsoft.com/en-us/library/ms188385.aspx
15133 Points
3647 Posts
Oct 07, 2010 11:42 AM|LINK
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.
vjagades
Member
91 Points
90 Posts
need of Ascending order based on the Date and month.
Oct 07, 2010 11:22 AM|LINK
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(); }Thanks& Regards
Jagadeesh Velusamy
MetalAsp.Net
All-Star
112229 Points
18266 Posts
Moderator
Re: need of Ascending order based on the Date and month.
Oct 07, 2010 11:34 AM|LINK
Add an ORDER BY clause.
Refer: http://msdn.microsoft.com/en-us/library/ms188385.aspx
KumarHarsh
All-Star
15133 Points
3647 Posts
Re: need of Ascending order based on the Date and month.
Oct 07, 2010 11:42 AM|LINK
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.
Kumar Harsh