Forum Academy Marketplace Showcase Pricing Features

Can I Pass order by value in SQL connector as a dynamic parameter

I am trying to pass the order by value dynamically, Say in this case I want to determine whether I want to do asc or desc on the column called “Date” depending upon a filter on the frontend. Though it is not throwing any error in the SQL connector, it doesn’t seem to be working.

Any idea on how this can be achieved?

I don’t think you can pass SQL column names as parameters. However, you have a few options.

  1. To achieve in SQL, I think you can use the Case statement in your order by clause. You’d have to play with it, but it looks like you have some SQL experience so I bet you can get it by testing it in your SQL environment and then putting it into Bubble. Something like

order by Case
when ? = ‘A’ then Date end ASC
else Date end DESC

  1. Remove the order by in your SQL statement and do the sort in Bubble by filtering the repeating group. If it’s not a lot of data, this will perform fine. But I do think it’s always better to do the ordering in your SQL statement if possible.

  2. Create different SQL Queries in Bubble. then in your workflow, call one of them to do the sort ASC and the other to do the sort DESC.

Joey

1 Like

@joeyg Thanks for the reply.

As you mentioned, I played around with Case conditions and was able to get that done. I could not use bubble filtering because it fetches 200 rows then filters on it, which doesn’t work in my case.

Thanks!

This topic was automatically closed after 70 days. New replies are no longer allowed.