SQL-SERVER CONVERT COLIMNS TO ROWS

علی ذوالفقار
1402/02/24 17:08:39 (380)
use CROSS APPLY : 

SELECT 
	COID 
	, SYEAR 
	, ITEMNAME 
	, ITEMVALUE 
	-- , MALIYAT
	-- , SOODE_KHALES
	-- , SARMAYEH 
FROM TBL_ARZYABI_AMALKARD_SHERKAT T 
	CROSS APPLY
	( 
		VALUES
		( 'TAX'	, MALIYAT ),
		( 'PROF'	, SOODE_KHALES ),
		( 'SAR' 	, SARMAYEH )
	) 
	C ( ITEMNAME , ITEMVALUE )
WHERE T.COID = 47 

SELECT COID , SYEAR , ITEMNAME , ITEMVALUE -- , MALIYAT -- , SOODE_KHALES -- , SARMAYEH FROM TBL_ARZYABI_AMALKARD_SHERKAT T CROSS APPLY ( SELECT 'TAX' , MALIYAT UNION ALL SELECT 'PROF' , SOODE_KHALES UNION ALL SELECT 'SAR' , SARMAYEH ) C ( ITEMNAME , ITEMVALUE ) WHERE T.COID = 47
Back