sql server stored procedure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I need to get data from a sql server database. Currently, user executes a sql
server query exists that creates an output file, which he saves. It is then
imported to Access mdb.

What would be the simplest & quickest way to automate this task? I am
leaning towards having the server guys amend the code & schedule the task. Or
should i create a pass-through query & recreate the code? I am not up to
speed yet on sql server, and my pass-through query experience is limited.

Thanks for any & all help.

patti
 
patti said:
I need to get data from a sql server database. Currently, user
executes a sql server query exists that creates an output file, which
he saves. It is then imported to Access mdb.

What would be the simplest & quickest way to automate this task? I am
leaning towards having the server guys amend the code & schedule the
task. Or should i create a pass-through query & recreate the code? I
am not up to speed yet on sql server, and my pass-through query
experience is limited.

Can you explain the reason that the data is put in an output file (and what
exaclty an output file is?)?

If your SQL Server "query" is actually a stored procedure then one with an
identical structure except that it returns a result set should be able to be
executed with a passthorugh query from your app and the data would be returned.

Is the current process used because the SP takes a long time to run? The output
could be placed into a SQL Server table and then you could link to that table
or pull it in with a passthrough query using a simple SELECT statement. If the
process is long then yes, it could be scheduled to run nightly. At any rate,
querying or linking to the data would almost certainly be better than importing
it unless you need it in your app when you have no access to the server.
 
Thanks Rick-

I am really just starting to learn & interact w/ sql server.

Is it a stored procedure? I guess i am not clear on the definition then. It
is a query that user runs once a week, when he supplies a date & then when
query is done, supplies a file name.

By output file, i meant he saves the results of the query to a text file. It
is then imported & appended to a master table. This is done because (i was
told) the data from the sql server db is archived frequently.

My theory was that the sql serverquery could be coded so that current date
is picked up, query is executed & data is written to a text file in an
accessible directory. Then sql server would schedule job/task to run.
Am i way off base?
 
patti said:
Thanks Rick-

I am really just starting to learn & interact w/ sql server.

Is it a stored procedure? I guess i am not clear on the definition
then. It is a query that user runs once a week, when he supplies a
date & then when query is done, supplies a file name.

Technically SQL Server does not have an object called a query. You have Views
and Stored Procedures. Views are similar to SELECT queries in Access, but they
don't DO anything. Stored Procedures are what you use in SQL Server to perform
operations. They can delete, insert, and update simlar to action queries in
Access, but have an entire procedural language (T-SQL) which allows them to do
many of the things that would be done in Access in a VBA procedure or function.
They can have variables, build temp tables, execute If-then type of logic etc..

Almost certainly what you user is running is a stored procedure.
By output file, i meant he saves the results of the query to a text
file. It is then imported & appended to a master table. This is done
because (i was told) the data from the sql server db is archived
frequently.

My theory was that the sql serverquery could be coded so that current
date is picked up, query is executed & data is written to a text file
in an accessible directory. Then sql server would schedule job/task
to run.
Am i way off base?

All of that should be possible yes. SQL Server has a separate service called
Agent that can be used to run "jobs" on a defined schedule. A Job can certainly
execute a stored procedure.
 
Thanks Rick.

I am trying to automate some daily, weekly tasks done by user working w/
access.

I am just starting to learn & interact w/ sql server.

Perhaps i don't know the real definition of a stored procedure.

User launches sql server query, is prompted for date, query runs, user saves
file as text file to accessible directory.

I was told that the sql server data is frequently archived.

I was thinking the sql server crew code amend the query code to start, to
grab current date, execute & then save data as text file to the necessary
directory.
And then schedule the job/task. (Am i far off base on this process?) Because
this sql server query is already in place & been thoroughly tested and used,
i was hoping sql server could automate this.


Or do i go w/ pass-throughs & create tables in access, thereby not having to
worry about archived data?

am i making sense?

patti
 
patti said:
Thanks Rick.

I am trying to automate some daily, weekly tasks done by user working
w/ access.

I am just starting to learn & interact w/ sql server.

Perhaps i don't know the real definition of a stored procedure.

User launches sql server query, is prompted for date, query runs,
user saves file as text file to accessible directory.

Okay, this sounds like an Access query that uses links to SQL Server tables as
its input. If he were actually using a passthrough query to run a stored
procedure on the server he would not get a prompt as only local Access queries
have the ability to prompt the user for input.

Then you indicate that the data is being returned from the server in real time
and the USER is the one creating the text file to be imported. You should be
able to eliminate that step entriely. The result set of the query should be
able to be directly appended to your local table.

Is the user doing this in your application or in a different one?
I was told that the sql server data is frequently archived.

Sounds like a poor design then. Since SQL Server can hold terrabytes of data I
don't see why archiving should ever be necessary.
I was thinking the sql server crew code amend the query code to
start, to grab current date, execute & then save data as text file to
the necessary directory.
And then schedule the job/task. (Am i far off base on this process?)
Because this sql server query is already in place & been thoroughly
tested and used, i was hoping sql server could automate this.

If a SQL Server stored procedure was used (which now sounds like it is NOT the
case) then all of that is possible.
Or do i go w/ pass-throughs & create tables in access, thereby not
having to worry about archived data?

If the data on the server is only there temporarily then you need to worry about
archived data no matter what you do in Access.
am i making sense?

Only partially I'm afraid. Any chance you can provide the SQL of the query this
user is running?
 
Yes- He is using a third party tool. I have not been given access to the app
so i'm not as well-informed as i should be. Will clarify the clients' reason
against using pass-through queries.

I will get the code and post it. And start brushing up on my pass-through
queries.
Definitely now leaning this way.

A question on your response to:
I was thinking the sql server crew code amend the query code to
start, to grab current date, execute & then save data as text file to
the necessary directory.
And then schedule the job/task. (Am i far off base on this process?)
Because this sql server query is already in place & been thoroughly
tested and used, i was hoping sql server could automate this.
case) then all of that is possible.
How can it be converted to a sp? Code the date and filename? I want this
view/query to run weekly, with an eye towards doing it on a daily basis.

Your help is greatly appreciated.

Man, rick, i could ask you lots more questions...i am learning from all the
postings here.
 
Hi Rick-

Here is the code........


select th.av_transaction_id as transaction_id,

th.store_no as hidden_store_no,

th.store_no, th.register_no,

'00000000000000000000' as customer_no,

th.transaction_date,

th.transaction_no,

sum((tl.gross_line_amount - tl.pos_discount_amount) * db_cr_none *
-1) as gross_amount,

sum((tl.gross_line_amount - tl.pos_discount_amount) * db_cr_none *
-1) as discount_amount,

'z1000000000000000000' as line_note, th.cashier_no

into #dd_dc

from mm.dbo.av_transaction_header th,

mm.dbo.av_transaction_line tl

where th.av_transaction_id = tl.av_transaction_id

and th.store_no between {{FromStore%}} and {{ToStore%}}

and th.transaction_date between {{FromDate*}} and {{ToDate*}}

and th.transaction_void_flag = 0

and tl.line_void_flag = 0

and tl.line_object_type = 1

and th.av_transaction_id in (select distinct av_transaction_id

from mm.dbo.av_transaction_line

where line_object in (10,126,300,304))

group by th.av_transaction_id, th.store_no,th.store_no, th.register_no,

th.transaction_date, th.transaction_no, th.cashier_no



update #dd_dc

set #dd_dc.discount_amount = tl.gross_line_amount

from mm.dbo.av_transaction_line tl, #dd_dc

where tl.av_transaction_id = #dd_dc.transaction_id

and tl.line_object in (10,126,300,304)



update #dd_dc
set #dd_dc.line_note = SUBSTRING(ln.line_note, 1, 20)
from mm.dbo.av_line_note ln, #dd_dc, av_transaction_line tl where
ln.av_transaction_id = #dd_dc.transaction_id
and ln.av_transaction_id = tl.av_transaction_id
and tl.line_object in (10,126,300,304)
and tl.line_id = ln.line_id




update #dd_dc

set #dd_dc.customer_no = isnull(c.customer_no,0)

from mm.dbo.av_customer c, #dd_dc

where c.av_transaction_id = #dd_dc.transaction_id



insert into #dd_dc

select th.transaction_id as transaction_id,

th.store_no as hidden_store_no,

th.store_no, th.register_no,

'00000000000000000000' as customer_no,

th.transaction_date,

th.transaction_no,

sum((tl.gross_line_amount - tl.pos_discount_amount) * db_cr_none *
-1) as gross_amount,

sum((tl.gross_line_amount - tl.pos_discount_amount) * db_cr_none *
-1) as discount_amount,

'z1000000000000000000' as line_note, th.cashier_no

from mm.dbo.transaction_header th, mm.dbo.transaction_line tl

where tl.transaction_id = th.transaction_id

and th.store_no between {{FromStore%}} and {{ToStore%}}

and th.transaction_date between {{FromDate*}} and {{ToDate*}}

and th.transaction_void_flag = 0

and tl.line_void_flag = 0

and tl.line_object_type = 1

and th.transaction_id in (select distinct transaction_id

from mm.dbo.transaction_line

where line_object in (10,126,300,304))

group by th.transaction_id, th.store_no, th.store_no, th.register_no,

th.transaction_date, th.transaction_no, th.cashier_no



update #dd_dc

set #dd_dc.discount_amount = tl.gross_line_amount

from mm.dbo.transaction_line tl, #dd_dc

where tl.transaction_id = #dd_dc.transaction_id

and tl.line_object in (10,126,300,304)


update #dd_dc
set #dd_dc.line_note = SUBSTRING(ln.line_note, 1, 20)
from mm.dbo.line_note ln, #dd_dc, transaction_line tl where
ln.transaction_id = #dd_dc.transaction_id
and ln.transaction_id = tl.transaction_id
and tl.line_object in (10,126,300,304)
and tl.line_id = ln.line_id


update #dd_dc

set #dd_dc.customer_no = isnull(c.customer_no,0)

from mm.dbo.customer c, #dd_dc

where c.transaction_id = #dd_dc.transaction_id


select * from #dd_dc

drop table #dd_dc


-------------------------------------

i want to save the data to a table because i query it before i append to the
master. and i want to code the date & store#'s.

so should i push to get the sql server side code it & schedule it or do i go
w/ access pass-through query & windows task scheduler?

your opinion please?

thanks,

patti
 
patti said:
Hi Rick-

Here is the code........
[snip]

Where did you pull that from?

It looks like T-SQL from a stored procedure that returns a result after doing
lots of operations on a temp table. You should be able to call that directly
from your Acces app with a passthrough query and feed the result into an append
query that will add it the data to your local table.

If you know the name of the stored procedure all you need is a passthrough query
with...

EXEC StoredProcName
 
this is the view/query that the user launches in their third party app.

I had requested access to their app but the client was hesitant. this is my
first consulting job & i felt that i needed to see all things currently being
run so that i could better assess the automation process. was i out of line?

thanks for all your help.

Rick Brandt said:
patti said:
Hi Rick-

Here is the code........
[snip]

Where did you pull that from?

It looks like T-SQL from a stored procedure that returns a result after doing
lots of operations on a temp table. You should be able to call that directly
from your Acces app with a passthrough query and feed the result into an append
query that will add it the data to your local table.

If you know the name of the stored procedure all you need is a passthrough query
with...

EXEC StoredProcName
 
Back
Top