Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

How best to do this?  (Task Scheduler that *triggers* SQL command that *triggers* stored procedure)

Posted on 2016-08-16
3
Medium Priority
?
65 Views
Last Modified: 2016-08-16
Hi - thanks for looking.

What I am looking for is to call upon the experts to see what the best method for doing this is.

I basically need to run an SQL script daily..

SELECT     Code FROM   FF_TALLY_TABLE
WHERE     (Optio_Concat IS NULL)

If there are any records.. I need to pass "Code" into a stored procedure for each record.


Store Procedure name is:

Optio_Concat


That's it.  I'm just not sure the best way to go about it.  Would like to call upon the Experts for this one for the most efficient way.
0
Comment
Question by:SmashAndGrab
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 41757700
0
 

Author Comment

by:SmashAndGrab
ID: 41757831
Guy - I have tried the DB cursor but I get the error.. am I missing something?

error
0
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 41757850
my article is actually about NOT using a cursor ...


so, it should be like this:
-- starting with the variables you will need in the processing part
declare @code int 

-- here is the table variable definition, which lives only for the duration of the run and is cleaned up automatically
-- for "small" results, it will stay purely in memory; larger sets may be "stored" in the temp database
declare @c table ( code int  )
-- fill the table with data, update your select as you need it
-- if your process requires some "order" in the processing, still an ORDER BY here will be useless (unless you also use and need a TOP X clause) see below on where you have to put the ORDER BY

set nocount on
insert into @c (code)
SELECT     Code FROM   
FF_TALLY_TABLE
WHERE     (Optio_Concat IS NULL)
 and Code  is not null

-- process, either if the above insert did at least 1 row, or if the below "delete" did indeed 
while @@ROWCOUNT <> 0
begin
  -- fetch 1 record from the table. 
  -- if your process requires some "order" in the processing, put the corresponding ORDER BY here
  select top 1 @code= code  from @c

  if @@ROWCOUNT <> 0
  begin
     exec Optio_Concat @code
  end

  -- here we delete the row from the temp table , which is nothing else than a processing queue table, hence
  delete @c where code = @code
END -- end of loop

Open in new window

0

Featured Post

 [eBook] Windows Nano Server

Download this FREE eBook and learn all you need to get started with Windows Nano Server, including deployment options, remote management
and troubleshooting tips and tricks

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question