45-48 动态加载CSVsheet/给sql 传递参数

2023-11-25  本文已影响0人  山猪打不过家猪

45 动态加载csv sheet(untill的使用)

46 给sql query传递动态参数

很重要的知识点:

@concat('select * from Sales where Country= ''',pipeline().parameters.p_country,'''')

中的引号的含义可以理解为

DECLARE @p_country NVARCHAR(255) = 'USA'; 
DECLARE @sql NVARCHAR(MAX);

SET @sql = 'SELECT * FROM Sales WHERE Country = ''' + @p_country + '''';

EXEC(@sql);

其中''' + @p_country + '''是一部分,表示了

'USA'

最后一个引号是和第一个select前的引号一个整体

SET @sql = '  SELECT * FROM Sales WHERE Country = ''' + @p_country + '''    ';
@concat('select * from Sales where Country = ''',pipeline().parameters.p_country,'''','and Region = ''',pipeline().parameters.p_region,'''')

这个表达式的工作方式如下:

select * from Sales where Country = 'France' and Region = 'Europe'

在这个最终的 SQL 查询字符串中,'France' 是 SQL 查询中的字符串字面量,它的单引号是通过 SQL Server 语句中的两个连续单引号表示的。

'select * from Sales where Country ='''+'usa'+'''' 
  1. 创建copy程序,这里比较难的在于sql是动态的,需要使用上面1的参数,动态sql如下
@concat('select * from Sales where Country = ''',pipeline().parameters.p_country,'''','and Region = ''',pipeline().paremeters.p_region,'''')
上一篇 下一篇

猜你喜欢

热点阅读