Solved

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

Posted on 2016-08-16
3
47 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 500 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql 2014,  lock limit 5 47
Problem when I run a simple storeproc - help 4 30
Re-appearing SQL Server Agent jobs 7 43
Split string into 3 separate fields 5 22
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
SQL Server engine let you use a Windows account or a SQL Server account to connect to a SQL Server instance. This can be configured immediatly during the SQL Server installation or after in the Server Authentication section in the Server properties …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

726 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