Use dymamic sql queries - examples here Execute Dynamic SQL commands in SQL Server[^] or here - SQL Server Dynamic SQL[^]
Edit: Apologies for not reading your question properly
Quote:
I want to take every nth row to get a series of rough data.
You can do something like this
;;;WITH CTE AS
(
select
ROW_NUMBER() OVER (ORDER BY [DateTime]) as rn,
Value1, Value2, Value3
FROM CKLog
WHERE DateTime > $__timeFrom() AND DateTime < $__timeTo()
)
SELECT *
FROM CTE
WHERE (rn % @n) = 0
order by rn;
Where
@n
is your "nth" calculation.
Incidentally using
Value1 as "Value1",
is pointless, just using
Value1,
will give exactly the same result. Also note the use of [ ] around the reserved word
DateTime
when it is used as a column name