How to get last UpdateDate/sysLoadDatetime on records as part of result when executing a stored procedure - stored-procedures

Hi I'm pretty much a beginner in SQL, but I would like to know if there is a way to know how old are the records contained in the stored procedure.
For example, if I execute a stored procedure, is there an extra statement that I can add to be able to see this last update date on each row?
When I run the stored procedure, it doesn't have a column that shows that information, but at least I would like to know how old is the data that is displaying.

Related

Totals that fall outside of the query

Newbie to access here.
I'm having an issue that I can't quite get my head around.
I have a very simple db for recording accounting transactions.
It contains, one table for the transactions, one query that returns the transaction amounts between two dates (with a total) and a report that shows the results of the query.
My issue is that I'm trying to add a total for ALL records into the report but I can't figure out how to do it without it just showing the totals from the query.
I've tried referencing the table directly but it returns a name error
I'd like to be able to do this without using VBA or SQL, any help would be most appreciated.
Thanks

db2 can you change cursor resultset in same stored procedure?

I have a stored procedure and which selects data from the database using
DECLARE cursor1 CURSOR WITH RETURN for SELECT...
OPEN cursor1
At this point I would like to delete and change records in the resultset in the same stored procedure. I cannot make these changes in the select.
Can this be done?
I have seen
DELETE WHERE CURRENT OF cursor1
but Data Studio does not like the syntax and underolines 'OF' as an error. I believe the version of Data Studio is only a couple of months old.
Thanks for any help or guidance.
You cannot change the result set without modifying the table itself. When issuing DELETE or UPDATE WHERE CURRENT OF you are actually deleting or updating rows in the underlying table.
Using WHERE CURRENT OF implies looping over the rows in the result set. Note that once you change the cursor position, the new position will be returned to the caller. In other words, after you consume the result set in the procedure itself, you will need to open the cursor once again in order to return the result set to the caller.

Maximum number of arguments that a stored procedure should receive

I have a web form from where I insert data to Oracle. There are at least 20 fileds on the form. For INSERT I want to use Stored Procedure. But in this case for VALUES section of the INSERT statement I need to send that many- in this case 20 parameters. Is this normal for a procedure to receive 20 parameters? If it's not, then what way should I follow to perform this? I know technically there's no problem but is this normal programming or database managementwise? I think this is the basic thing all web developer do all the time.

pyodbc return multiple cursors from stored procedure with DB2

I have a python program that calls a stored procedure from db2 database. I am using results = cursor.fetchall() to process the results of my stored procedure. However, my stored procedure returns two cursors. results only contains the first one. I need a way to loop through as many cursors as I want. I was hoping fetchmany() would be my answer but it is not.
I need to be able to do multiple result sets as the program I am writing can only call one stored procedure. It would take a lot to go back and make it to be able to call two. Besides with one of these things I need to make 10 cursors return. Everything is dynamic, so the application doesn't know what procedure it is running, it just gets the data and spits it into excel not knowing the meaning. I need one cursor for the data, and the other cursors for different types of counts and totals.
I am looking for a built in function to do this, or maybe even a different library because I have done my share of googling and it looks like pyodbc does not do this for DB2. DB2 is a requirement.
Use the nextset() method of the cursor: https://github.com/mkleehammer/pyodbc/wiki/Cursor#nextset
Sample code:
# fetch rows from first set
rows = cursor.fetchall()
# process first set rows here
# advance to next result set
while (cursor.nextset()):
# fetch rows from next set, discarding first
rows = cursor.fetchall()
# process next set rows here
nextset() will return True if additional result sets are available, and subsequent cursor fetch methods will return rows from the next set. The method returns None if no additional sets are available.
Just a small simplification for the record:
while True:
rows = cursor.fetchall()
# process all result sets in the same place
if not cursor.nextset():
break

Reporting Services - Determine whether or not Stored Procedure returns garbage fields

I have to develop a report against Sybase and I am calling a stored procedure for the dataset using an exec statement in a text query.
This stored procedure, instead of returning no records when there are none available, returns a table with a different column structure than that which is returned when records are available.
This causes all of my fields to display #ERROR. Is there a way to determine that the data set is going to return this garbage row so that I can hide the rows that are effected and handle the error?
Thanks so much for your help.
Frank
The solution for this is to check the IsMissing property on the dataset field:
Set the row's "Hidden" property to -
=IIF(Fields!FieldThatShouldBeThere.IsMissing,true,false)
Frank

Resources