欄位排序
ALTER FUNCTION [dbo].[Test_1]
(
@feild nvarchar(50)
)
returns table
AS
RETURN
(
select feild,[1] as "col1",[2] as "col2",[3] as "col3",[4] as "col4",[5] as "col5"
from (select top 100 feild,ROW_NUMBER() over(order by value1) as RowNo, value1
from (SELECT feild,col1 ,col2 ,col3 ,col4 ,col5 from test1 where feild=@feild) a
unpivot (value1 for col in ([col1],[col2],[col3],[col4],[col5])) as unpvt order by value1) b
pivot (sum(value1) for RowNo in ([1],[2],[3],[4],[5])) as pvt
)
ALTER PROCEDURE [dbo].[Test_RowSort]
AS
BEGIN
select Row_Number() over(order by feild) RowNo,feild into #test from test1
declare @i int,@temp nvarchar(50)
select @i=1
while @i<=(select Max(RowNo) from #test)
begin
select @temp= feild from #test where RowNo=@i
set @i=@i+1
update test1 set col1=a.col1,col2=a.col2,col3=a.col3,col4=a.col4,col5=a.col5
from [dbo].[Test_1](@temp) a where test1.feild=@temp
end
END
(
@feild nvarchar(50)
)
returns table
AS
RETURN
(
select feild,[1] as "col1",[2] as "col2",[3] as "col3",[4] as "col4",[5] as "col5"
from (select top 100 feild,ROW_NUMBER() over(order by value1) as RowNo, value1
from (SELECT feild,col1 ,col2 ,col3 ,col4 ,col5 from test1 where feild=@feild) a
unpivot (value1 for col in ([col1],[col2],[col3],[col4],[col5])) as unpvt order by value1) b
pivot (sum(value1) for RowNo in ([1],[2],[3],[4],[5])) as pvt
)
ALTER PROCEDURE [dbo].[Test_RowSort]
AS
BEGIN
select Row_Number() over(order by feild) RowNo,feild into #test from test1
declare @i int,@temp nvarchar(50)
select @i=1
while @i<=(select Max(RowNo) from #test)
begin
select @temp= feild from #test where RowNo=@i
set @i=@i+1
update test1 set col1=a.col1,col2=a.col2,col3=a.col3,col4=a.col4,col5=a.col5
from [dbo].[Test_1](@temp) a where test1.feild=@temp
end
END
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/7899089/viewspace-614276/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- mysql中文欄位排序MySql排序
- MySQL 按照指定的欄位排序MySql排序
- SQL字元型欄位按數字型欄位排序實現方法SQL字元排序
- Spring MVC @SortDefault多欄位排序SpringMVC排序
- LINQ 按多個欄位排序排序
- jQuery對Table一個欄位排序jQuery排序
- 逆向工程通過某個欄位排序排序
- MySql Order By 多個欄位 排序規則MySql排序
- mysql5.6生成排序欄位MySql排序
- PHP陣列多個欄位分別排序PHP陣列排序
- 快排實現仿order by多欄位排序排序
- 欄位按照指定 ID 順序進行排序排序
- 二維陣列根據欄位進行排序陣列排序
- 二維陣列根據某個欄位排序陣列排序
- 請教一下 多欄位值如何排序?排序
- PHP指定欄位的多維陣列排序方法PHP陣列排序
- C# 實現list=list.OrderBy(q=>q.欄位名).ToList(); 按多個欄位排序C#排序
- 使用正規表示式對數字字串欄位排序字串排序
- PHP 二維陣列, 按某一個欄位排序PHP陣列排序
- ElasticSearch多欄位權重排序居然可以這麼玩Elasticsearch排序
- Java stream sorted使用 Comparator 進行多欄位排序Java排序
- js記一個根據欄位排序物件函式JS排序物件函式
- PHP二維陣列根據某個欄位排序PHP陣列排序
- pydantic 欄位欄位校驗
- 哇,ElasticSearch多欄位權重排序居然可以這麼玩Elasticsearch排序
- SpringJpa @query 中根據傳入引數(欄位)排序Spring排序
- varchar型別的欄位儲存純數字的排序型別排序
- Sql 查詢 置頂、排序,置頂和非置頂為不同的排序欄位SQL排序
- asp.net Repeater拖拽實現排序並同步排序欄位到資料庫中ASP.NET排序資料庫
- laravel-query-builder 對於欄位 值為 null的排序方式LaravelUINull排序
- hadoop streaming 按欄位排序與輸出分割詳解Hadoop排序
- fastadmin 新增欄位記圖片欄位AST
- php 對二維陣列的某個欄位公用排序的方法PHP陣列排序
- [BUG反饋]模型管理 > 欄位管理看不見任何欄位。這表明顯有欄位、!模型
- 【Mongo】mongo更新欄位為另一欄位的值Go
- sql語句修改欄位型別和增加欄位SQL型別
- oracle刪除表欄位和oracle表增加欄位Oracle
- C語言-對一個結構體中的欄位進行排序C語言結構體排序