从Excel创建SQL存储过程脚本 [英] Create a SQL Stored procedure script from Excel

查看:127
本文介绍了从Excel创建SQL存储过程脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Excel中有一个数据源,我有一个格式化的sql sp脚本。 

I have a data source in Excel and I have a formatted sql sp script. 

我想了解如何通过每列读取excel并格式化SP相应地为每一行编写脚本并使用C#写入文本文件

I want to understand how can I read excel by each column and format SP script accordingly for each row and write to a text file using C#

此外,如果任何列值为零,则应跳过在脚本中添加的行。

Also if any colum value is zero, it should be skipped from getting added in the script.

对于前。我有excel中的数据

For ex. I have data in excel as

Col1 Col2 Col3 Col4 Col5

Col1 Col2 Col3 Col4 Col5

1      0      1      23    1

1      0      1      23    1

1        1      2      231    3

1       1      2     231   3

我的脚本应该准备好了

usp_savemydata @ Col1 = 1,@ Col3 = 1,@ Col4 = 23,@ Col5 = 1

usp_savemydata @Col1=1, @Col3=1, @Col4=23, @Col5 = 1

usp_savemydata @ Col1 = 1,@ Col2 = 1,@ Col3 = 3,@ Col4 = 231,@ Col5 = 3

usp_savemydata @Col1=1, @Col2=1, @Col3=3, @Col4=231, @Col5 = 3




推荐答案

关于"我有格式化的sql sp脚本",请更具体。作为格式化的存储过程(如果你的意思是sp)真的没有意义,重要的是它是有效的。

Please be more specific in regards to "I have a formatted sql sp script" as formatted stored procedure (if that is what you mean by sp) really does not make sense, what matters is it works.

你也可以考虑指出有多少行和列如果列中的所有数据从上到下都是相同的,因为这些数据可以在人们如何回复阅读和检查您的Excel数据时发挥作用。

You might also consider indicating how many rows and columns there are and if all data in columns is the same from top to bottom as these can play a part in how one might reply for reading and inspecting your excel data.


这篇关于从Excel创建SQL存储过程脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆