我需要用查詢中的一些文本替換數字。sql替換1行中的值
我使用此代碼
SELECT [hostname]
,[assetTag]
,[business]
,[building]
,replace([Building],'700','ICT') AS BuildingNR
,replace([Building],'879','Sales') AS BuildingNR
FROM [osdDB].[dbo].[all_machines]
這是輸出
hostname assetTag business building BuildingNR BuildingNR
ICT103961 A62609 ICT_IMO_E_M 879 879 Sales
ICT107826 A72752 ICT_IMO_SALES 700 ICT 700
ICT108923 A73433 ICT_IMO_SALES 700 ICT 700
ICT113735 A86955A ICT_IMO_IS 879 879 Sales
ICT108071 A73642 ICT_IMO_SALES 706 706 706
ICT110732 A86111 ICT_IMO_SALES 700 ICT 700
ICT108929 A73427 ICT_IMO_SALES 700 ICT 700
ICT109648 A72895A ICT_IMO_MRN 700 ICT 700
ICT110919 A86778 ICT_IMO_SALES 700 ICT 700
ICT102048 B81606A ICT_IMO_SALES 700 ICT 700
但我想這個輸出
hostname assetTag business building
ICT103961 A62609 ICT_IMO_E_M Sales
ICT107826 A72752 ICT_IMO_SALES ICT
ICT108923 A73433 ICT_IMO_SALES ICT
ICT113735 A86955A ICT_IMO_IS Sales
ICT108071 A73642 ICT_IMO_SALES ICT
ICT110732 A86111 ICT_IMO_SALES ICT
ICT108929 A73427 ICT_IMO_SALES ICT
ICT109648 A72895A ICT_IMO_MRN ICT
ICT110919 A86778 ICT_IMO_SALES ICT
ICT102048 B81606A ICT_IMO_SALES ICT
當我使用它,我得到太多的行。我只想把它全部放在一排。
plz發佈所需的輸出和完整的查詢。如果你創建一個sqlfiddle –
並且完整的查詢 –
返回的行數取決於你的'WHERE'子句,那將會更好。發佈剩餘的查詢。 – Coderchu