# How can use a field in jdbc statement of jdbc streaming

**URL:** https://discuss.elastic.co/t/how-can-use-a-field-in-jdbc-statement-of-jdbc-streaming/169942
**Category:** Logstash
**Created:** [February 26, 2019, 5:08am UTC](https://discuss.elastic.co/t/how-can-use-a-field-in-jdbc-statement-of-jdbc-streaming/169942 "2019-02-26T05:08:14Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![sahere37](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@sahere37](https://discuss.elastic.co/u/sahere37)
#### Post date: [February 26, 2019, 5:08am UTC](https://discuss.elastic.co/t/how-can-use-a-field-in-jdbc-statement-of-jdbc-streaming/169942/1 "2019-02-26T05:08:14Z")

</div>

hi all,  
I am using following logstash.conf file:

```auto
input {
jdbc {
    jdbc_driver_library => "F:\driver\sqljdbc_6.0\enu\jre8\sqljdbc42.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://local:3333;databaseName=TotalTXN"
    jdbc_user => "sss"
    jdbc_password => "sss"
    statement => "
	DECLARE @DDate1 CHAR(10)
   select @DDate1=REPLACE(MAX(Date),'/','') from TotalTXN.dbo.TotalTxn_Control
   select TOP 10 [BaseDate_Accept_Setel]
  ,[Financial_Date]
     from dbo.vw_TotalTXN where (BaseDate_Accept_Setel<=@DDate1) AND (BaseDate_Accept_Setel> :sql_last_value)
	"
use_column_value => "true"
tracking_column => "basedate_accept_setel"
}

}
filter {
        mutate {
		add_field => {"s_date" => "%{financial_date}"}
}		 
jdbc_streaming {
 jdbc_driver_library => "F:\driver\sqljdbc_6.0\enu\jre8\sqljdbc42.jar"
    jdbc_driver_class => "com.microsoft.sqlserver.jdbc.SQLServerDriver"
    jdbc_connection_string => "jdbc:sqlserver://local:3333;databaseName=TotalTXN"
    jdbc_user => "sss"
    jdbc_password => "sss"
    parameters => {"mine" => "%{s_date}"}
    statement => "
	DECLARE @DDate2 CHAR(10)
	set @DDate2=:mine
SELECT TotalTXN.dbo.d2md(@DDate2) as gdate"
target => "gdate"
}
mutate { replace => { "gdate" => "%{[gdate][0][gdate]}" } }
    mutate { gsub => ["gdate", "/", "-"] }
}

output {
  elasticsearch { 
    hosts => ["http://192.168.170.153:9200"]
    index => "a10_%{gdate}"
    user => "logstash_internal25"
    password => "x-pack-test-password"
 }
  stdout { codec => rubydebug }
}

```

where Financial\_Date is earned in jdbc input statement, i want to use the value of this field in jdbc streaming statement.  
when i used following statement, it works and is ok.

```auto
DECLARE @DDate2 CHAR(10)
	set @DDate2='2019/02/24'
SELECT TotalTXN_OnLine.dbo.d2md(@DDate2) as gdate

```

but using (set @DDate2=:mine) doesn't work, how can i handle this issue? any advice will be so appreciated. many thanks.

---

<div class="post-metadata">

### Author: ![yaauie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/yaauie/32/23363_2.png) [@yaauie](https://discuss.elastic.co/u/yaauie)
#### Post date: [February 26, 2019, 11:13pm UTC](https://discuss.elastic.co/t/how-can-use-a-field-in-jdbc-statement-of-jdbc-streaming/169942/2 "2019-02-26T23:13:08Z")

</div>

> [@sahere37](#):
>
> ```auto
> parameters => {"mine" => "%{s_date}"}
> 
> ```

I believe you're looking for:

```auto
parameters => {"mine" => "s_date"}

```

The key/value map supplied by `parameters` matches a SQL-parameter name to a Event-field name, not a sprtintf template.

---

<div class="post-metadata">

### Author: ![sahere37](https://avatars.discourse-cdn.com/v4/letter/s/b2d939/32.png) [@sahere37](https://discuss.elastic.co/u/sahere37)
#### Post date: [February 27, 2019, 5:01am UTC](https://discuss.elastic.co/t/how-can-use-a-field-in-jdbc-statement-of-jdbc-streaming/169942/3 "2019-02-27T05:01:21Z")

</div>

Many thanks. it works

---

<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: [March 27, 2019, 5:01am UTC](https://discuss.elastic.co/t/how-can-use-a-field-in-jdbc-statement-of-jdbc-streaming/169942/4 "2019-03-27T05:01:25Z")

</div>

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