Photo of Miqueas Nieves

0

SQL & ROWS

The following sql sorts my data exactly as expected (I am using an HTML file).

How do I perform the same sort on the rows? (I am a new person learning these IT lingo)

This is my sql:

{% sql %}

SELECT [LastName], [FirstName] FROM [Person] ORDER BY [LastName], [FirstName]

{% endsql %}

{% for item in results %}

      {% assign q = q | Plus:1 %} 

     {{ q }} {{ item.LastName }}, {{ item.FirstName }} 
{% endfor %}


I did try:

{% sql %}

     SELECT [LastName], [FirstName] FROM [Row] ORDER BY [LastName], [FirstName]

{% endsql %}

I received the following error: Liquid error: Invalid object name 'Row'

How do I perform the same sort on the rows?



  • Michael Garrison

    If this is all you're doing on this page, you may want to consider using the Dynamic Data block instead of the HTML block: you'd only need to give it the one SELECT line and it would nicely format the output for you. Omit {% sql %}, {% endsql %} and all of the loop you've used to display the results.

  • Photo of Michael Garrison

    0

     Miqueas,

    In your SQL statement, FROM needs to point to a SQL table. Row is not a SQL table, Person is.

    The results from your first query should be coming out sorted by last name, then firstname where the lastname is identical. Is that what you're seeing?

    I don't understand what the second query is for, so I'm assuming that you're not getting the order you expected from the first query. Can you post a sample of what you're getting from the first query and explain what you want different?

    Edit: You're also not limiting how many people it's listing. With a usual number of people in your database, this is going to return a HUGE amount of data. Do you really want a list of EVERYONE in your database, regardless of their connection status, inactive/deceased status, etc?