V
V
Vitaly Rybchenko2017-08-10 17:50:21
SQL Server
Vitaly Rybchenko, 2017-08-10 17:50:21

Can a common table expression (with as) be used twice?

Hello!
Is it possible to use a common table expression twice? If so, how?

//выбираем только 20 строк с ... по ...
with DATAS as (select Id, Name, row_number() over (order by Id) RN from Country )
select * from DATAS where RN between 10 and 30 
//считаем сколько всего записей
select count(*) from DATAS

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Skorzhinsky, 2017-08-11
@AndyKorg

Look at the t-sql documentation
.... fetched when executing a simple query and defined in the execution scope of a single SELECT, INSERT, UPDATE or DELETE statement.....

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question