473,402 Members | 2,050 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Update table with result from stored procedure/query?

I have a table that I insert data into using the following stored procedure:
Expand|Select|Wrap|Line Numbers
  1. CREATE PROCEDURE [dbo].[usp_insertTotaler] 
  2. AS
  3. BEGIN
  4.     SET NOCOUNT ON;
  5.  
  6.         DECLARE @Periode DateTime, @NyPeriode DateTime
  7.     SET @NyPeriode = (SELECT Max(Periode) FROM InstPeriode)
  8.  
  9.     IF EXISTS 
  10.         (SELECT DISTINCT ip.Periode FROM InstPeriode ip LEFT OUTER JOIN Totaler t ON ip.Periode = t.Periode 
  11.         WHERE t.Periode Is Null)
  12.     BEGIN
  13.     INSERT INTO Totaler(iNavn, Periode, SubBrutSum, BrutTotal)
  14.  
  15.     EXEC dbo.usp_displayThemAll
  16.     @Periode = @NyPeriode
  17.     SELECT iNavn, Periode, SubBrutSum, BrutTotal
  18.     FROM Totaler
  19.     END
My question is: Is it possible to make an updatequery that executes a stored procedure (usp_displayThemAll) and then update my table (Totaler) with these data? And if it is - then how?
Dec 15 '10 #1
3 7290
ck9663
2,878 Expert 2GB
Yes you can...

If you execute the display before the update, you're going to display the un-updated records.

Also, displaying the records will not do anything if you don't push it to your front-end. SQL Server is a Database, not a front-end tool...

Good Luck!!!

~~CK
Dec 15 '10 #2
It doesn't seem to me like I'm using SQL as a front-end tool? What's wrong with creating a stored procedure, and then push it to my front end? (Which is what I do - don't worry).

Perhaps I misunderstand you, but your answer seems a bit unkind...
Dec 16 '10 #3
ck9663
2,878 Expert 2GB
The comment was based on the assumption that your stored procedure is called DisplayAll. Which to me says the intention is to display the record.

If you want to update a table based on the resultset returned by that stored procedure, there are a number of options.

1. Read the stored proc, retrieve the query and use it to update your table.

2. Convert the stored proc into a table-valued function and then call it to insert to your table.

3. If you really want to use that stored procedure, you still can. Here, read this...

Happy Coding!!!

~~ CK
Dec 16 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Andrew J Durstewitz | last post by:
Hi! I'm not sure if you can do this but what I want to do it execute a stored procedure but query it with dynamic ASP data. Basically, exex StoredProc where id = 2 I am using a set of...
2
by: Mike Leahy | last post by:
Hello all, This question is related to updating tables - is there any way to calculate or update the values in a column in a table to the values in a field produced by a query result? An...
1
by: Lauren Quantrell | last post by:
I have read the newsgroups and see this is a common issue but I saw no resolution for it: I have an Access2K frotn end and SQL Server 2K backend. In access, I create a temp table using code in a...
9
by: joun | last post by:
Hi all, i'm using this code to insert records into an Access table from asp.net, using a stored procedure, called qry_InsertData: PARAMETERS Long, Long, Text(20), Long, DateTime; INSERT...
4
by: markbartolo | last post by:
Hi, I have the following: INSERT IGNORE INTO names (name) VALUES ('John'),('Peter'); In the above query, I want to pass an unknown amount of names to the insert query. I tried a stored...
0
by: justjazz | last post by:
I am successfully able to perform a direct sql/400 (in iseries) call to the delete statement DELETE FROM RDSUFAQA.SAPXFER but when I make a call to the same sql statement via a stored...
3
by: Penstar | last post by:
I'm sorry if this is a really stupid question, but I have just started using mySQL. I have created a basic stored proc, which does the following: SELECT * from members; I can call it from...
3
by: sonysunny | last post by:
Hai, I have a temporary table created in a stored procedure.How can i access that temporary table from another stored procedure. thanks in advance.
2
by: qwedster | last post by:
Folk! How to programattically check if null value exists in database table (using stored procedure)? I know it's possble in the Query Analyzer (see last SQL query batch statements)? But how...
1
by: hemantc87 | last post by:
i am using this stored procedure to update my gridview CREATE PROCEDURE . @Name varchar(20), @Course varchar(20), @Age numeric, @Sex varchar(20), @DateofBirth datetime, @Address ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.