Need the solution to solve taking string from the database and replacing the parameter.
Here are the sample queries I used to understand more:
--Create Table Table1
--(
--Id int primary key identity(1,1),
--Data varchar(max)
--)
--Create Table Table2
--(
--Id int primary key identity(1,1),
--SampleData varchar(max)
--)
Delete From Table1
GO
Delete From Table2
Go
insert into Table2 (SampleData) values ('How r u ''+@i+''. ')
Declare @i int = 100
Declare @TempSampleData varchar(max) = NULL
While(@i > 0)
begin
Set @TempSampleData = (select SampleData from Table2)
insert into Table1 (Data ) values (@TempSampleData)
insert into Table1 (Data) values ('How r u '+Cast(@i as varchar(500))+'.')
set @i = @i - 1
End
–Output
Id Data
103 How r u '+@i+'. --Needed output here is How r u 100.
104 How r u 100.
105 How r u '+@i+'.
106 How r u 99.
107 How r u '+@i+'.
108 How r u 98.
109 How r u '+@i+'.
110 How r u 97.
111 How r u '+@i+'.
How about something like this in your loop: