Go Premium for a chance to win a PS4. Enter to Win

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
?
71 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
  • 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

Visualize your virtual and backup environments

Create well-organized and polished visualizations of your virtual and backup environments when planning VMware vSphere, Microsoft Hyper-V or Veeam deployments. It helps you to gain better visibility and valuable business insights.

Question has a verified solution.

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

This is basically a blog post I wrote recently. I've found that SARGability is poorly understood, and since many people don't read blogs, I figured I'd post it here as an article. SARGable is an adjective in SQL that means that an item can be fou…
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…

916 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