I am doing something like this in SP,
insert into @FilteredTbl select * from @MasterTbl
but now problem is that i want data of @MasterTbl sorted before adding into @FilteredTbl,
How can I do that ?
Maybe something like this:
INSERT INTO @FilteredTbl
SELECT * FROM @MasterTbl AS tbl
ORDER BY tbl.OrderbyColumn
Try following method to insert sort result into temp table. Use ROW_NUMBER to ORDER BY table result
DECLARE @FilteredTbl AS TABLE
(
RowID INT
[Column_1]
[Column_2]
.
.
)
insert into @FilteredTbl
select ROW_NUMBER()OVER(ORDER BY [ShortColumn]),[Field_1],[Field_2]... from @MasterTbl
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With