Tag Info

New answers tagged

2

You need to initialize @FinalHistoricalQuery before the loop and you need to use it in on the left side if the assignment in the loop. declare @CurrentRow int set @CurrentRow =0; declare @RowsToProcess int declare @FinalHistoricalQuery varchar(5000) -- Set a start value set @FinalHistoricalQuery = '' WHILE @CurrentRow<3 BEGIN ...


0

After several experiments I am here answering my same question. This works as our traditional a = a + 1 method. Run queries one by one as below to understand the flow of task. Example1: Query 1: Below query returns 1@[id]. Meaning @a = 1@[id] Declare @a as varchar(4000) SET @a = 1 SELECT Top 1 @a = @a + '@' + '['+COLUMN_NAME+']' FROM ...


7

I am curious to know how the column names getting concatenated. Can't really answer that. Some internal workings of SQL Server creates a result like that, sometimes. The technique has been around for a considerable amount of time. Microsoft does not support the functionality and advises not to use it. From SET @local_variable (Transact-SQL) Do ...



Top 50 recent answers are included