我在一个完美运行的商店程序中有这个查询:
select dbo.fn_GetSid(@Cid,sid) as SIdPrfx,
dbo.fn_GetPId(@Cid, sid, pid) as PIdPrefix,
*
from #tempsafety
where (createddate >= @dateFrom or @dateFrom is null) and
(createddate<= @dateTo or @dateTo is null)
order by createddate desc
但我想更改顺序并将SIdPrfx和PIdPrefix放在选择输出的末尾
答案 0 :(得分:3)
我们可以这样做:
SELECT
*,
dbo.fn_GetSid(@Cid,sid) as SIdPrfx,
dbo.fn_GetPId(@Cid, sid, pid) as PIdPrefix
FROM #tempsafety
-- -- --
答案 1 :(得分:1)
您可以使用outer apply
:
select *
from #tempsafety
outer apply
(
select dbo.fn_GetSid(@Cid,sid) as SIdPrfx,
dbo.fn_GetPId(@Cid, sid, pid) as PIdPrefix
) sub
where (createddate >= @dateFrom or @dateFrom is null) and
(createddate<= @dateTo or @dateTo is null)
order by createddate desc