Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4051842
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T14:14:43+00:00 2026-05-20T14:14:43+00:00

I need to retrieve change-data-capture rows for several tables, and I’m required (by company

  • 0

I need to retrieve change-data-capture rows for several tables, and I’m required (by company IT policy) to access the database via stored procedures. I would rather create a single stored procedure with the table name as a parameter, rather than one stored procedure for each table I’m monitoring. Where I get hung up is that CDC defines a separate table-valued function name for each table monitored, and I’m not sure how best to generalize around that.

Is it possible to modify the following example code so that it invokes cdc.fn_cdc_get_net_changes_dbo_ + @Table instead of cdc.fn_cdc_get_net_changes_dbo_TABLE ?

Is there another approach I should use?

create proc [dbo].GetChangesForTable
 @Table varchar(50),
 @BeginTime datetime,
 @EndTime datetime
as
begin

    DECLARE @begin_lsn binary(10), @end_lsn binary(10); 
    DECLARE @func nvarchar(128)

    if @EndTime is null select @EndTime=GETDATE()

    SELECT @begin_lsn = sys.fn_cdc_map_time_to_lsn('smallest greater than', @BeginTime); 
    SELECT @end_lsn = sys.fn_cdc_map_time_to_lsn('largest less than or equal', @EndTime); 

     -- HOW TO GET THE CORRECT FUNCTION CALLED HERE?        
    SELECT * FROM cdc.fn_cdc_get_net_changes_dbo_TABLE(@begin_lsn, @end_lsn, 'all')

end
GO
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T14:14:43+00:00Added an answer on May 20, 2026 at 2:14 pm

    I think that’s possible with sp_executesql like that :

    DECLARE @sql nvarchar(4000)
        SET @sql = N'SELECT * FROM cdc.fn_cdc_get_net_changes_dbo_'+cast(@TABLE as varchar)+'(@begin_lsn, @end_lsn, 'all')'
    
    
    EXEC sp_executesql @sql, N'@Table varchar(50), @BeginTime datetime, @EndTime datetime',@Table,@BeginTime,@EndTime
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to retrieve random rows from SQL Server database. I am looking for
I need to retrieve data from two tables. the first is a list of
depending on what data I retrieve from the database, I need to update the
When in a method of a controller I need to retrieve some data from
i need to retrive some data from table registration of database to show.aspx page
I'm building a system that need to collect some user sensitive data via secured
I've changed my data model and need to change a property of all my
I have been searching for how to retrieve binary data from the database. My
I need to retrieve some data stored as varchar in an SQL table to
I need to display the text on Text Box whatever data retrieve from files.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.