temp table parameters

Shambhu Rai 1,406 Reputation points
2023-09-08T18:02:32.0833333+00:00

Hi Expert,

unable to understand the below query can someone explain me what is happening in below query

CREATE PROCEDURE [dbo].[THINKNEW] @CurrentVersion BIGINT, @LastVersion BIGINT                  

AS                  

BEGIN                  

  IF OBJECT_ID(N'tempdb..##RETHINK_temp') IS NOT NULL      ------??                

BEGIN                      

DROP TABLE #RETHINK_temp                

END      

select                        

RETHINK.NO,     

RETHINK.START_DATE,     

RETHINK.SourceSystemName    

INTO #RETHINK_temp                   

From RETHINK as RETHINK                

RIGHT OUTER JOIN CHANGETABLE (CHANGES RETHINK,                   

@LastVersion)   -----------unable to understand this                

as CT on       

RETHINK.NO=CT.NO     

AND RETHINK.START_DATE=CT.START_DATE    

AND RETHINK.SourceSystemName=CT.SourceSystemName    

where CT.SYS_CHANGE_VERSION <=                   

@CurrentVersion                   

and RETHINK.Isdeleted='Y'                  

DELETE RETHINK                  

FROM RETHINK RETHINK                  

INNER JOIN #RETHINK_temp RETHINK_temp                  

  ON      

RETHINK.NO=RETHINK_temp.NO     

AND RETHINK.START_DATE=RETHINK_temp.START_DATE    

AND RETHINK.SourceSystemName=RETHINK_temp.SourceSystemName       

and RETHINK.Isdeleted='Y'                  

END

GO


query:

1)the changetable is not any table then what is mentioned below

RIGHT OUTER JOIN CHANGETABLE (CHANGES RETHINK,                   @LastVersion)   -----------unable to understand this   


what does this below query means and two dots are saying

 IF OBJECT_ID(N'tempdb..##RETHINK_temp') IS NOT NULL  
Azure SQL Database
Azure SQL Edge
Azure SQL Edge
An Azure service that provides a small-footprint, edge-optimized data engine with built-in artificial intelligence. Previously known as Azure SQL Database Edge.
48 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
13,263 questions
SQL Server Integration Services
SQL Server Integration Services
A Microsoft platform for building enterprise-level data integration and data transformations solutions.
2,509 questions
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-09-08T19:40:47.3+00:00

    Changetable is bult-in SQL functionality for a db which has change tracking enabled.

    https://learn.microsoft.com/en-us/sql/relational-databases/system-functions/changetable-transact-sql?view=sql-server-ver16

    Object_ID uses a specific syntax - database_name . schema_name . object_name your example omits the schema name so using 2 . in a row is correct in this case.

    0 comments No comments

0 additional answers

Sort by: Most helpful