Query from SQL Server

Hi,

I am trying to get the result by using the below query

import "sql"

sql.from(
    driverName: "sqlserver",
    dataSourceName: "sqlserver://user:password@localhost:1433?database=examplebdb",
    query: "GO SELECT * FROM Example.Table",
)
|> filter(fn:(r) => r["column1"]=="values")
|> filter(fn:(r) => r["column2"]=="values")

Congrats, I guess?
I hope you succeed

Hi,

I have not succeed. I am not getting the output. For that I have posted. Is that query right or not?

I cannot tell you if it should return something, It depends on your SQL database. but it looks right to me.
also:
I dont know a lot of SQL but I am not sure the GO statement should be there.

also I use this syntax Instead:

 dataSourceName: "Server=localhost;Database=examplebdb;User Id=username;Password=pasword;",

but according to this, yours should work too.

Query SQL Server | Flux 0.x Documentation (influxdata.com)

do you have any error?
are you using yield() function at the end to show the data?

Hi,

The below query is ix of two queries in grafana with data source as flux

import "sql"
sql.from(
    driverName: "sqlserver",
    dataSourceName: "sqlserver://user:password@localhost:1433?database=examplebdb",
    query: "GO SELECT * FROM Example.Table",
)
|> filter(fn:(r) => r["column1"]=="values")
|> filter(fn:(r) => r["column2"]=="values")

First query is 
import "sql"
sql.from(
    driverName: "sqlserver",
    dataSourceName: "sqlserver://user:password@localhost:1433?database=examplebdb",
    query: "GO SELECT * FROM Example.Table",
)
it is to get the data from SQL Server into influx with data source as flux, which is working fine.
The second is flux query

|> filter(fn:(r) => r["column1"]=="values")
|> filter(fn:(r) => r["column2"]=="values")

I am trying to apply these filters for the query 1 and try to get the output.

If your data has column1 and column2 it should work.

I usually do it like you described. first query from SQL then use flux functions

Also, in my case the return data usually needs to be converted because everything returned from SQL is string, so numeric and _time values need to be converted. But I don’t think that is your problem here.