Click here to Skip to main content
16,004,574 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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
Posted
Updated 26-Feb-16 4:49am
v2

1 solution

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[^]
 
Share this answer
 
Comments
Member 10376341 27-Feb-16 4:14am    
Thank you for the reply Snorkie.
Am relatively new to this SQL am still figuring out how to implement the triggers for my query.
Can you please help me out in segregating the right code?

Thanks

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900