Skip to content

This project contains the GetTotalData SQL stored procedure, which dynamically counts records from multiple tables based on the current date. It iterates through a predefined table list, executes queries, and returns a summarized dataset.

Notifications You must be signed in to change notification settings

AlejandroMeyer/GetTotalData-SQL-Procedure

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 

Repository files navigation

GetTotalData SQL Procedure

About

This project contains an SQL stored procedure named GetTotalData, which is designed to extract and count records from a specified table based on a date filter. The procedure dynamically constructs SQL queries to count records for each table and stores the results in a temporary table before returning the final dataset.

Features

  • Uses a cursor to iterate over a list of tables.
  • Dynamically constructs and executes SQL queries.
  • Filters records based on the current date.
  • Stores and returns results in a temporary table.

How It Works

  1. Declares a temporary table #TempResult to store the results.
  2. Declares necessary variables for processing.
  3. Uses a cursor to iterate through the extraccions_test table to retrieve table names and related metadata.
  4. Dynamically constructs and executes a SQL query to count records where the date field matches the current date.
  5. Stores the results in the temporary table.
  6. Returns the final dataset.
  7. Cleans up by closing and deallocating the cursor.

Usage

To execute the stored procedure, use the following command in SQL Server:

EXEC GetTotalData;

About

This project contains the GetTotalData SQL stored procedure, which dynamically counts records from multiple tables based on the current date. It iterates through a predefined table list, executes queries, and returns a summarized dataset.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages