fixer-m / snowflake-db-net-client

Snowflake .NET Client
Apache License 2.0
51 stars 14 forks source link

Named Bind Parameters with IN clause #19

Closed eegasai closed 2 years ago

eegasai commented 2 years ago

I am trying to implement Bind parameters with the SQL query like example below (only with the named parameters)

var result5 = await snowflakeClient.QueryAsync<Employee>
              ("SELECT * FROM EMPLOYEES WHERE TITLE = :Title", new Dictionary<string, string> {{ "Title", "Programmer" }});

If I have a IN clause in SQL query how can I use the Bind parameter ? I have tried to create a comma separated string and bind it to the parameter, but its not working. Can you help with an example?

fixer-m commented 2 years ago

@eegasai Hi!

If you want to use named parameters with IN operator you can do it like this:

var result = await snowflakeClient.QueryAsync<Employee>     
              ("SELECT * FROM EMPLOYEES WHERE TITLE IN (:TitleA, :TitleB, :TitleC);", 
              new { TitleA = "Programmer", TitleB = "Janitor", TitleC = "CEO" });

However I think positional parameters fits for this task more naturally:

var result = await snowflakeClient.QueryAsync<Employee>     
              ("SELECT * FROM EMPLOYEES WHERE TITLE IN (?, ?, ?);", 
              new string[] { "Programmer", "Janitor", "CEO" });