My problem is that I want to merge two SPs in one. the skeleton of the resulting sp is:
with Paging(RowNo, ID, Name, Description, LengthSeconds, Rating, Url, ThumbnailFileName, AddedAt) AS
(
(if(@SortType is null)
begin
... select ...
end
else
begin
... select...
end
)
select * from Paging ...
Can I do that If in the with statement?
No,,, it would be something like
If the query is that simple though, then you wouldn’t need a CTE: it doesn’t add any readibility