Jump to content
Sign in to follow this  
SRod

Manipulate a query through a variable in SQL

Recommended Posts

Hello everyone,

In the code below I`m targeting a database called t_lg202001  which refers to a log table of a specific year and month. In this case January 2020. See code below:

SELECT a.EVTLGUID, a.DEVDT, a.USRID, c.NM, b.NM FROM t_lg202001 a 
JOIN t_evttyp b 
ON a.EVT = b.EVT 
JOIN t_usr c 
ON a.USRID = c.USRID
WHERE a.USRID IS NOT NULL
ORDER BY a.EVTLGUID DESC LIMIT 1;

As my target table is going to be update every month as the years goes by I need to change this line of code for every single month and afterwards years. i.e:

 t_lg202001  = January 2020.

t_lg202002  = February 2020.

...

...

...

t_lg202012 = December 2020

t_lg202101 = January 2021

...

..

t_lg202112 = December 2021. 

I really would like to manipulate that line of the code through a variable where I can automate as required.

Does anyone has any idea or how this can be done? 

If there isn`t any way at the moment here is a suggestion of improvement for the coming versions of the Unilogic software which I think it`d be very beneficial and it would enable the capability of the software for the future. 

I hope that makes sense. 

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...