Community Spring Cleaning week is here! Join your fellow Maveryx in digging through your old posts and marking comments on them as solved. Learn more here!

Alteryx Designer Desktop Discussions

Find answers, ask questions, and share expertise about Alteryx Designer Desktop and Intelligence Suite.
SOLVED

Filter In-DB - Filter data by Latest Date

PKoya
8 - Asteroid

Hi,

 

I am trying to use the In-DB tools for the first time and using MS SQL Server. 

 

Database I am using contains records for each month. Date is always the 1st of every month.

 

What query do I use to filter the date column by latest date?

 

Thank you!!!

 

18 REPLIES 18
TomWelgemoed
12 - Quasar

Hi @PKoya 

 

You should be able to do something like:

 

SELECT *
FROM [B2BSales].[dbo].[TicketSales]
where EventDate=(select max(EventDate) from [B2BSales].[dbo].[TicketSales])

 

In the case above, the bold text indicates where you need to put your own fields, i.e. TicketSales is your table and EventDate is whatever your datefield is called in that table

 

Hope that helps!

Tom

PKoya
8 - Asteroid

Thanks @TomWelgemoed for your reply.

 

I tried this earlier as well within Connect In_DB Tool the but I am getting the below error.

 

Error: Connect In-DB (1): Error: Microsoft OLE DB Provider for SQL Server: Unspecified error 

in Query: [My Query which is quite similar to yours.]

 

From what I have read online, I would need to use the Filter In-DB tool and use an SQL expression within it. That is the part where I am getting stuck.

AngelosPachis
16 - Nebula

Hi @PKoya ,

 

An alternative would be to find the max date in your dataset with a Summarize In-DB tool and then do an Inner Join with the main stream of data

 

AngelosPachis_0-1614329292447.png

 

Cheers,

 

Angelos

 

TomWelgemoed
12 - Quasar

Hi @PKoya,

 

Your issue may be related to your connection itself - does it work if you simply do something like the below?

 

SELECT top 1 *
FROM [B2BSales].[dbo].[TicketSales]

 

If your issue is with the database, try to see if you can fix that first and then of course the query will work OK. If it's not that (and the query above works), I think you may just have a SQL syntax issue. Feel free to post your query back on here so we can check that if your database connection is fine.

 

Best,

Tom

PKoya
8 - Asteroid

When doing SELECT * FROM dbo, the data is pulling through fine but just the filter part is causing the issue.

 

Bear in mind that I am not using conventional Input tool but the Connect In-DB option.

 

However, the method suggested by @AngelosPachis worked like a charm. 🙂 

PKoya
8 - Asteroid

Thank you for your suggestion, @AngelosPachis. It worked like a charm for this particular application. 🙂

TomWelgemoed
12 - Quasar

Hi @PKoya ,

 

Great to hear. Then it must simply be the syntax on the SQL query - if you can, test it in the database to see if it better pinpoints the error. 

 

Only reason it matters is that your performance should be improved if you write the query in one script...but that only matters of course if you have a big data set.

 

All the best!

Tom

AngelosPachis
16 - Nebula

No worries @PKoya ,

 

I would be interested to know however why the query suggested by @TomWelgemoed  is not working 😕

 

Maybe if we could bring more people in the convo they can help us understand what's wrong  (looking at you @echuong1  and @BrandonB  🙂 )

PKoya
8 - Asteroid

Absolutely!!!

 

I will try and replicate the solution suggested by @TomWelgemoed and post the error/screenshot.

 

I am also keen to get the filter working within the query as I am thinking of some other places I want to use In-Database tools.

Labels