sql - Assign value of a column in a table as columname of another table -
I have a parent table table structure like this I have to show this way Can anyone help? There are several ways that you can convert data from rows to columns. A If you have a limited number of values that you call columns You can hardly query: SRC Pivot for saltype_name in u_id, Basic, HRA, DA (Original, HRA, DA), select But if you have unknown numbers, then you want to apply dynamic SQL to generate results: View. Both give result to questions: SalType and
Saltype_name Is the column name Another table
StaffSal that
StaffSal I enter values for each SalType_name
Saltaip --table 1 Ss_aid Saltaip_nam 1 Basic 2 HRA 3 DA StaffSal --table2 SV_id SS_id SV_value U_id 2 1 15000 11 3 2 0.1 11 4 3 0.75 11 5 1 10000 12 6 2 0.01 12 7 3 0.5 12
U_id Basic HRA DA ... 11 15000 1.75 12 10000.01.5
PIVOT function in SQL Server that can be applied to rotate the data
(max ( Sv_value)), excluding STOTP, except STOTP, name, SU_ID, SS_View, excluding PIV (TS_ID = s.ss_id);
SLAPAN order by SASID from SALTIPE group by SASID (XML path to) (code)) TYPE) Kvalue ( 'K', 'NVARCHAR (MAX)), 1,1' ') set @query =' sELECT u_id, '+ from @cols +' (selection Do tty_type_name, s. (for '+ saltype_name in @ Cos +') x pivot (maximum sv_value)) p 'execute (@query)
| U_ID | Basic | HRA | DA | ------------------------------ | 11 | 15000 | 0.1 | 0.75 | | 12 | 10000 | 0.01 | 0.5 |
Comments
Post a Comment