【问题标题】:Parametrized query with Snowflake and pass the values from Snowflake .NET Connector使用 Snowflake 进行参数化查询并从 Snowflake .NET 连接器传递值
【发布时间】:2021-03-15 06:59:33
【问题描述】:

像 MySQL 和 SQL Server 一样使用 Snowflake 创建参数化。需要从 .NET Snowflake .NET 连接器传递值。

https://www.mssqltips.com/sqlservertip/2981/using-parameters-for-sql-server-queries-and-stored-procedures/

查询值:

select * 
from "SNOWFLAKE_SAMPLE_DATA"."TPCDS_SF100TCL"."WEB_SITE" 
where ((Web_REC_START_DATE is null and IFF('2000-08-16' is null,true,false))    
       or Web_REC_START_DATE > '2000-08-16')

How to use SqlDataReader with a parametrized query in c#?

使用参数名称查询:

select * 
from "SNOWFLAKE_SAMPLE_DATA"."TPCDS_SF100TCL"."WEB_SITE" 
where ((Web_REC_START_DATE is null and IFF(@StartDate is null,true,false)) 
       or Web_REC_START_DATE > @StartDate)

【问题讨论】:

    标签: snowflake-cloud-data-platform


    【解决方案1】:

    雪花 .net 连接器托管在 github 中,我在 bind-parameter 部分中描述了如何使用

    所以看看代码中的测试,特别是BindTest line 75

    它显示正在使用的命名参数。因此:

    command.CommandText = "insert into TEST_TBL values(:p0)";
    var param = command.CreateParameter();
    param.ParameterName = "p0";
    param.DbType = System.Data.DbType.Int32;
    param.Value = DBNull.Value;
    command.Parameters.Add(param);
    

    【讨论】:

    • 我想创建带有命名参数的查询,就像 MySQL 和 MS SQL 支持的查询一样。
    猜你喜欢
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-06-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多