I'm building this dynamic sql but getting an error when executing it.
Conversion failed when converting the varchar value 'SELECT
DDoSAttacksId,
AttackId,
TargetIP,
PeakBPS,
DateStarted
FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY DateStarted Desc) AS Row,
DDoSAttacksId AS DDoSAttacksId,
AttackId AS AttackId,
TargetIP As TargetIP,
CONCAT(PeakBPS / 1000000000,' Gbps') As PeakBPS,
DateStarted AS DateStarted
FROM
DDosAttacks
WHERE TargetIP IN ('108.61.51.101', '206.221.181.5')) AS DDosAttacksRows
WHERE
(Row between (' to data type int.
Note: It plugs in the IPAddress just fine, but not the integer values.
set quoted_identifier off
declare @sql nvarchar(4000),
@PageNumber int,
@PageSize int,
@IPAddressList varchar(100)
Select @IPAddressList = "'108.61.51.101', '206.221.181.5'"
select @sql= 'SELECT
DDoSAttacksId,
AttackId,
TargetIP,
PeakBPS,
DateStarted
FROM (
SELECT
ROW_NUMBER() OVER (ORDER BY DateStarted Desc) AS Row,
DDoSAttacksId AS DDoSAttacksId,
AttackId AS AttackId,
TargetIP As TargetIP,
CONCAT(PeakBPS / 1000000000,'' Gbps'') As PeakBPS,
DateStarted AS DateStarted
FROM
DDosAttacks
WHERE TargetIP IN ('+@IPAddressList+')) AS DDosAttacksRows
WHERE
(Row between ('+@PageNumber+' * ('+@PageSize+' - '+@PageSize+')) AND ('+@PageNumber+' * ('+@PageSize+' - 1)))';
EXECUTE sp_executesql @sql
I can hard code numbers in their place it and executes fine....for example (Row between (1 * (20 - 20)) AND (1 * (20 - 1)))';