Это то, что вы хотите .. Оба запроса дают одинаковые результаты
Стиль 1
SELECT IDs
,Company
,FORMAT(YearFormed, 'yyyy') AS YearFormed
,Amount
FROM
(SELECT C.IDs, C.Company, CONVERT(DATE, C.YearFormed) AS YearFormed, CONVERT(MONEY, C.Amount) AS Amount FROM temp.dbo.CompanyInfo AS C) AS RC
WHERE Amount IS NOT NULL
Стиль 2
WITH RESULT AS --3-I named this query with the intention to formart the Year in which the companies were formed
(
SELECT IDs --1-Started from here
,Company
,CONVERT(DATE, C.YearFormed) AS YearFormed --2-I converted to Date here so I couldnt run format too so
,CONVERT(MONEY, C.AMOUNT) AS Amount
FROM temp.dbo.CompanyInfo AS C
WHERE C.AMOUNT IS NOT NULL
)
SELECT R.IDs
,R.Company
,FORMAT(R.YearFormed, 'yyyy') AS YearFormed --4-I used this SELECT statement only to format this column
,R.Amount
FROM RESULT AS R
Вот что получается в результате