将数据从A列导出到基于B列的文本文件中

发布于 2025-01-21 10:26:50 字数 844 浏览 2 评论 0原文

我希望使用来自Excel的数据来填充许多SQL脚本。

在一个列中有一个用户名列表。
在相邻的列中,有一个位置列表。

我有一个SQL脚本的模板,并且需要为每个位置生成一个TXT文件,并插入相关用户。

例如,如果这是数据集:

和此脚本模板:

locationa

Update usertable
set counduct_locked ='1'

中的用户ID (%locationa_users%);

locationb

更新可用的
set counduct_locked ='1'

中的用户ID (%locationb_users%);

输出将需要这样:

locationa

更新Usertable
set counduct_locked ='1'

中的用户ID ('user1','user2','user3','user4','user5');

locationb

更新可用的
set counduct_locked ='1'

中的用户ID ('user6','user7','user8','user9','user10','user11','user12');

它可以导出到一个文件,但每个位置都带有一个单独的脚本,或每个位置单独的文件。

I am looking to populate a number of SQL scripts using data from Excel.

In one column there is a list of usernames.
In an adjacent column, there is a list of locations.

I have a template of a SQL script, and I need a TXT file generated for each location, with the relevant users inserted.

For example, if this were the data set:
enter image description here

And this the script template:

LOCATIONA

update USERTABLE
set ACCOUNT_LOCKED = '1'
where USERID in
(%LOCATIONA_USERS%);

LOCATIONB

update USERTABLE
set ACCOUNT_LOCKED = '1'
where USERID in
(%LOCATIONB_USERS%);

The output would need to be like this:

LOCATIONA

update USERTABLE
set ACCOUNT_LOCKED = '1'
where USERID in
('User1','User2','User3','User4','User5');

LOCATIONB

update USERTABLE
set ACCOUNT_LOCKED = '1'
where USERID in
('User6','User7','User8','User9','User10','User11','User12');

It could either export to a single file, but with a separate script for each location, or a separate file per location.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

狼亦尘 2025-01-28 10:26:50

我创建了一个具有一些公式的类似数据集。您可以激发自己的灵感,以获取所需的东西:

  • A列包含位置的名称。
  • B列包含用户的名称。
  • C列过滤器上的“位置”,该公式在C1中显示。
  • D列在“ locationb”上过滤器,公式(如D1所示)类似于C1中的公式。
  • textjoin基于“位置”和“ locationb”的用户列表,使用公式(= textjoin(“,”,true,true,c2:c6)< /code>)在值之前显示:

”在此处输入图像说明”

I have created a similar dataset, with some formulas. You can inspire yourself on this in order to get what you need:

  • Column A contains the names of the locations.
  • Column B contains the names of the users.
  • Column C filters on "LocationA", the formula is shown in C1.
  • Column D filters on "LocationB", the formula (shown in D1) is similar to the one in C1.
  • A TextJoin based formula is used for collecting the list of users, both for "LocationA" and "LocationB", the formula (=TEXTJOIN(",",TRUE,C2:C6)) is shown preceeding the values:

enter image description here

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文