Solved

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

Posted on 2016-08-16
3
39 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 142

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 142

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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Columnstore Indexes - real-time operational analytics 1 35
Generate Weekly Schedule 15 29
Help Required 2 32
Need help how to find where my error is in UFD 6 30
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 …
Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backup…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.

777 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