Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

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 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.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now