# Is it possible to create a dynamic table name in statement of jdbc input plugin in Logstash?

**URL:** <https://discuss.elastic.co/t/is-it-possible-to-create-a-dynamic-table-name-in-statement-of-jdbc-input-plugin-in-logstash/336846>\
**Category:** Logstash\
**Tags:** jdbc\
**Created:** [June 25, 2023, 7:00pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-a-dynamic-table-name-in-statement-of-jdbc-input-plugin-in-logstash/336846 "2023-06-25T19:00:11Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![rabih](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabih/32/122733_2.png) [@rabih](https://discuss.elastic.co/u/rabih)\
**Post date:** [June 25, 2023, 7:00pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-a-dynamic-table-name-in-statement-of-jdbc-input-plugin-in-logstash/336846/1 "2023-06-25T19:00:11Z")

</div>

```auto
input {
  jdbc {
    jdbc_connection_string => "jdbc:sqlserver://ip_address:1433;databaseName=database_name;encrypt=true;trustServerCertificate=true;"
    jdbc_user => "userxxxx"
    jdbc_password => "passxxxx"
    jdbc_driver_library => "logstash-core/lib/jars/mssql-jdbc-12.2.0.jre8.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    statement => "SELECT * FROM DeviceLogs_5_2023 WHERE DeviceLogId > :sql_last_value ORDER BY DeviceLogId ASC"
    schedule => "* * * * *"
    tracking_column => "devicelogid"
    use_column_value => true
    type => "devicelogs"
  }
}

```

Here, in statement table name is DeviceLogs\_5\_2023. But it will change according to the present month and year.

Is there any way to make the name of table name in statement dynamically?  
Or any other methods?

---

<div class="post-metadata">

**Author:** ![eMitch](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/emitch/32/93607_2.png) [@eMitch](https://discuss.elastic.co/u/eMitch)\
**Post date:** [June 25, 2023, 7:51pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-a-dynamic-table-name-in-statement-of-jdbc-input-plugin-in-logstash/336846/2 "2023-06-25T19:51:18Z")

</div>

Hey @rabih and welcome to the community!

If you want that kind of logic, you may be better off creating a stored procedure in mssql which has some dynamic SQL to produce the table name.

Then in logstash you can call `statement => "EXEC dbo.stored-proc-name @lastvalue = :sql_last_value"`

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 23, 2023, 7:52pm UTC](https://discuss.elastic.co/t/is-it-possible-to-create-a-dynamic-table-name-in-statement-of-jdbc-input-plugin-in-logstash/336846/3 "2023-07-23T19:52:15Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
