如何自动执行sql查询。 [英] How to automatically execute sql queries.

查看:81
本文介绍了如何自动执行sql查询。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello All,



我有一个Table1,基于它我创建了Table2,其中包含所有公式和复杂性。这里我需要在将一些数据输入Table1时执行这些查询。



怎么可能?



基本上,我已经给出了一个文件(excel文件)上传选项在ASP.NET中,将excel文件数据存储到数据库中。现在,我需要在Table1上执行某些查询,以获取要存储在Table2中的操纵数据。每当用户在Table1中上传新数据时就会发生这种情况,因此Table2将定期更新。



它是否可以在C#中使用存储过程。

喜欢,在Button Click事件中给出一个SQL命令



在SQL服务器中自行执行它。



我希望能很好地解释我的问题。

我将非常感谢可溶性答案。



谢谢

Saiekrishna



我尝试过:



我的查询示例需要自动执行:



INSERT INTO Table2

SELECT field1],

count(当[field2] ='No Value'然后1结束时的情况)作为Results_1,
sum(当[field3]为空时的情况,然后是0,否则1结束)作为Result_2,

count(当[field4] ='是'然后1结束时的情况)作为Result_3,

sum([field5] ='0'然后0其他1结束时的情况)as as Result_4,

FROM Table1

Hello All,

I have a Table1 and based upon it i created Table2 with all the formulas and complexity. Here i need to execute those queries whenever some data is entered into the Table1.

How it is possible?

Basically, i have given a file(excel file) upload option in the ASP.NET which stores the excel file data into the database. Now i need to execute certain queries on the Table1 for fetching manipulated data to be stored in Table2. And this has to occur whenever a user uploads a new data in Table1, hence Table2 will be regularly updated.

Will it work using a stored procedure in C#.
Like, giving a SQL commands in Button Click Event
Or
Executing it in SQL server it self.

I hope am clear in explaining my problem.
Soluble answers will be greatly appreciated.

Thanks
Saiekrishna

What I have tried:

Example of my query which needs to be automatically executed:

INSERT INTO Table2
SELECT field1],
count(case when [field2] = 'No Value' then 1 end) as Results_1,
sum(case when [field3] IS NULL then 0 else 1 end) as Result_2,
count(case when [field4] = 'Yes' then 1 end) as Result_3,
sum (case when [field5] = '0' then 0 else 1 end) as Result_4,
FROM Table1

推荐答案

您正在寻找的是触发器。它们基于插入/更新/删除自动执行。它们易于实施。看看下面的文章。



触发器简介 - 第一部分 - SQLTeam.com [ ^ ]
What you're looking for is a trigger. They execute automatically based on Insert/Update/Delete. They are easy to implement. Check out the article below.

An Introduction to Triggers -- Part I - SQLTeam.com[^]


这篇关于如何自动执行sql查询。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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