Invalid SQL query in property "orderby"

Eric Conklin asked on September 16, 2020 20:45

I am trying to query blog posts on my website using a data source web part.

Using a SQL where clause in my data source I am doing the following to grab by category from the query string:

('{%ToInt(QueryString.categoryid, "")#%}' = 0 AND '{%categoryname%}'='') OR (DocumentID IN (SELECT DocumentID FROM CMS_DocumentCategory WHERE CategoryID = {% ToInt(QueryString.categoryid) #%}))

From there I want to order by BlogPostDate in descending order, so I go into my order by clause in the data source web part and add the following:


I am getting an error every single time stating it is an invalid SQL query. How can I make this query work with the where and the order by clause?

Correct Answer

Liam Goldfinch answered on September 16, 2020 21:33

Hi Eric,

Is this happening because you are putting an entire order by statement in the order by field, e.g. ORDER BY BlogPostDate DESC

You shouldn't need the ORDER BY part, try again with just BlogPostDate DESC

0 votesVote for this answer Unmark Correct answer

   Please, sign in to be able to submit a new answer.