久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

如何透視列并在之后更新透視數據

How to pivot columns and update the pivoted data afterwards(如何透視列并在之后更新透視數據)
本文介紹了如何透視列并在之后更新透視數據的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我有一個包含以下列的表格:

I have a table with the following columns:

GLLink int
Budget01 float
Budget02 float
Budget03 float
Budget04 float
Budget05 float
Budget06 float
Budget07 float
...
Budget57 float
Budget58 float
Budget59 float
Budget60 float

由于我的過濾器,每列有 8 行.

For each column, there is 8 rows because of my filter.

所有這些列都有值.

我需要將每一列的值設置為零,但是我知道我需要旋轉數據然后更新?

I need to set each columns value to zero, however I have the understanding that I would need to pivot the data and then update afterwards?

我知道您可以在 Excel 中轉置結果,然后在 Excel 中開發您的查詢,但是,我想知道如何在不使用 Excel 的情況下實現這一點.

I know you can just transpose the results in Excel and then develop you query in Excel, however, I would like to know how to achieve this without using Excel.

在 Excel 中轉置后,我的更新查詢將如下所示:

After the transpose in Excel, my update query would look like this:

update Budgets set Budget01 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget02 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget03 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget04 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget05 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget06 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget07 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
...
update Budgets set Budget57 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget58 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget59 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')
update Budgets set Budget60 = 0 where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')

我如何需要在 SQL 中開發相同的更新查詢,而不使用 Excel 并考慮以上所有內容?

How would I need to develop the same update query in SQL, without using Excel and taking all of the above in consideration?

推薦答案

使用一個更新來統治他們所有

Use the One Update To Rule Them All

update Budgets 
set 
Budget01 = 0,
Budget02 = 0,  
Budget03 = 0,  
...
Budget59 = 0,
Budget60 = 0
where GLLink in (select AccountLink from Accounts where Master_Sub_Account like '3200>%')

或者使用動態 SQL

Or use Dynamic SQL

示例:

declare @Cols NVARCHAR(max);
declare @DynSql NVARCHAR(max);

SELECT @Cols = concat(@Cols+', ',char(10), Col.Name, '=0')
FROM SYS.OBJECTS Obj
JOIN SYS.COLUMNS Col ON Obj.OBJECT_ID = Col.OBJECT_ID
WHERE Obj.TYPE='U' 
  AND Obj.NAME = 'Budgets'
  AND Col.Name LIKE 'Budget[0-9][0-9]';

set @DynSql = N'update Budgets set '+ @Cols + char(10) +
'where GLLink in (select AccountLink from Accounts where Master_Sub_Account like ''3200>%'')';

exec(@DynSql);

db<>fiddle 此處上進行測試

Test on db<>fiddle here

這篇關于如何透視列并在之后更新透視數據的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Modify Existing decimal places info(修改現有小數位信息)
The correlation name #39;CONVERT#39; is specified multiple times(多次指定相關名稱“CONVERT)
T-SQL left join not returning null columns(T-SQL 左連接不返回空列)
remove duplicates from comma or pipeline operator string(從逗號或管道運算符字符串中刪除重復項)
Change an iterative query to a relational set-based query(將迭代查詢更改為基于關系集的查詢)
concatenate a zero onto sql server select value shows 4 digits still and not 5(將零連接到 sql server 選擇值仍然顯示 4 位而不是 5)
主站蜘蛛池模板: 91麻豆精品国产91久久久久久 | 日韩欧美国产综合 | 国产一区二区三区在线看 | 精品欧美一区二区三区久久久 | 国产成人精品免费视频大全最热 | 亚洲日韩中文字幕一区 | 在线播放国产一区二区三区 | 免费看大片bbbb欧美 | 日本一卡精品视频免费 | 亚洲一区二区三区乱码aⅴ 四虎在线视频 | 成人福利片 | 久久久久国 | 日本精品一区二区三区四区 | 国产一区二区三区四区在线观看 | 免费一区 | 精品一二三区在线观看 | 国产a级毛毛片 | 国产日产欧产精品精品推荐蛮挑 | 91精品国产99久久 | www.日本在线播放 | 国产精品久久久久久久久久 | 国产在线h| 中文福利视频 | 在线一区视频 | 国内自拍偷拍 | 超碰精品在线 | 国产乱人伦 | 九九久久久 | 亚洲 欧美 综合 | 草草草草视频 | 影音先锋中文字幕在线观看 | 日韩精品在线看 | 亚洲精品久久久一区二区三区 | 国产精品久久久久永久免费观看 | 视频一区二区国产 | av色站 | 国产日屁| 亚洲品质自拍视频 | 亚洲欧美在线一区 | 国产一区二区三区色淫影院 | 久久国产精品一区二区三区 |