Advertisement

04.28.2008 at 10:24AM PDT, ID: 23359449
[x]
Attachment Details

Need help writing stored proc in Firebird DB

Asked by Nugs in Interbase / Firebird Database

This is more of a request for help than a specific question. I have zero experience writing stored procedures in Firebird but have run into a situation where it might be best that I return this type of data using a stored proc rather than the current method I am using.

Basically what I am requiring is a count of records for each day in a date range. So for example if a user puts in 4/25/08 to 4/28/08, currently my C# code will loop through each day of the range and request a count from the database. So we are talking about a separate query for each day of that is requested& This is done with the with the attached code snippet.

This method returns an ArrayList of my counts for any table I need and any date range I need& But performance wise it stinks. And these queries can range over 90 days or 90 counts&

SO& this is where I need help. I would like to have a stored proc that will do a query like this for me. I would like a stored proc that I could run that would give me a TABLE of counts in sequence of the days requested. It must return a table as my C# code will need to loop through it and would not know the original sequence. It would also be nice if this stored proce was flexable enough to accept any table name and field names for the date comparison.

Would anyone be kind enough to help me with this? I am not really even sure the work involved or anything on the subject really.

Much appreciated

Nugs
Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
public ArrayList GetRecordCounts(string TableName, string DateField, int NumberOfDays, DateTime StartingFrom)
        {
            ClassLib.Database_Interface.DBQueries DbQuery = new ClassLib.Database_Interface.DBQueries();
            ArrayList RecordCounts = new ArrayList();
 
            for (int i = 1; i <= NumberOfDays; i++)
            {
                string Query = "SELECT Count(*) FROM " + TableName + " WHERE " + DateField + " = '" + StartingFrom.AddDays(i * -1).ToShortDateString() + "'";
                RecordCounts.Add(DbQuery.RunSelect(Query.ToString()).Rows[0]["COUNT"].ToString());
            }
 
            return RecordCounts;
        }
 
 
[+][-]04.28.2008 at 12:13PM PDT, ID: 21456756

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: Interbase / Firebird Database
Sign Up Now!
Solution Provided By: imfallible
Participating Experts: 1
Solution Grade: A
 
 
[+][-]04.28.2008 at 12:32PM PDT, ID: 21456919

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 12:37PM PDT, ID: 21456957

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 12:51PM PDT, ID: 21457069

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 01:03PM PDT, ID: 21457160

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 01:20PM PDT, ID: 21457284

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 01:29PM PDT, ID: 21457351

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 01:39PM PDT, ID: 21457430

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 01:43PM PDT, ID: 21457453

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 01:49PM PDT, ID: 21457496

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 01:53PM PDT, ID: 21457529

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628