# Logstash sql\_last\_start with sql server

**URL:** <https://discuss.elastic.co/t/logstash-sql-last-start-with-sql-server/61380>\
**Category:** Logstash\
**Created:** [September 23, 2016, 12:08pm UTC](https://discuss.elastic.co/t/logstash-sql-last-start-with-sql-server/61380 "2016-09-23T12:08:16Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![mhensen](https://avatars.discourse-cdn.com/v4/letter/m/41988e/32.png) [@mhensen](https://discuss.elastic.co/u/mhensen)\
**Post date:** [September 23, 2016, 12:08pm UTC](https://discuss.elastic.co/t/logstash-sql-last-start-with-sql-server/61380/1 "2016-09-23T12:08:16Z")

</div>

I am running in a little problem..I want to have logstash picking up changes of multiple datatables

Therefor I have created multiple config files and did an initial filling without the :sql\_last\_start  
This works ok.. and all config files have ran..

But now I have a DateLastModified column and want to get only the records that have changed after the sql\_last\_start.

I have managed to have the sql\_last\_start save by using last\_run\_metadata\_path ..  
But there the problem starts.. if I add the DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), DateLastModified) \>= :sql\_last\_start I will get an sql error about conversion..  
Looking at the value in the file I see --- 2016-09-23 11:16:40.874000000 Z I think that this would be the problem  
How can I have the correct dateformat here .. yyyy/MM/dddd HH:mm:ss:nnn ?

I want to have based on the sql\_last\_start as I have multiple configs that also will depend on the sql\_last\_start!  
With last\_value it might be that changes will be missed as it can be that the value is set by a later config.

Or can I have the last value stored in a 'per config' log file?! just like the sql\_last\_start?!?

Here is a section of the config:`statement => "Select contactid,genderid,Email, DateLastModified from Contact where contactTypeid=1 and contactStatusid=1 and DATEADD(second, DATEDIFF(second, GETDATE(), GETUTCDATE()), DateLastModified) >= ':sql_last_start'" schedule => "* * * * * *" jdbc_paging_enabled => true jdbc_page_size => "5000" record_last_run => true last_run_metadata_path => "C:\Apps\logstash-5.0.0\log\logstash_jdbc_last_run_contact" type => "log"`

error is:←[33mException when executing JDBC query {:exception=\>#\<Sequel::DatabaseError: Java::ComMicrosoftSqlserverJdbc::SQLServerException: Conversion failed when converting date and/or time from character string.\>, :level=\>:warn}←[0m

Somebody any ideas as I cannot find any answer anywhere!!

---

<div class="post-metadata">

**Author:** ![magnusbaeck](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/magnusbaeck/32/44943_2.png) [@magnusbaeck](https://discuss.elastic.co/u/magnusbaeck)\
**Post date:** [September 26, 2016, 7:55pm UTC](https://discuss.elastic.co/t/logstash-sql-last-start-with-sql-server/61380/2 "2016-09-26T19:55:56Z")

</div>

> error is:←[33mException when executing JDBC query {:exception=\>#, :level=\>:warn}←[0m

Is that _really_ all that's in your log? There's no error message after "#"?

---

<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 6, 2017, 4:36am UTC](https://discuss.elastic.co/t/logstash-sql-last-start-with-sql-server/61380/3 "2017-07-06T04:36:48Z")

</div>


