I have the below code in which I am first creating a temp table and the second is part of a dynamic query I have in which I am creating a header row for my table by querying tempdb.sys.Columns
.
The issue I have is that I am not sure how to alias the table columns so if the column is say ItemDesc, then I want the header to say "Item Description".
create table #FeesCalculation
(
ItemId char(20),
ItemDesc varchar(max),
Units varchar(600) ,
Rate decimal(18,3),
Frequency varchar(60),
Annual decimal(18,3),
BasedOn nvarchar(max)
)
SELECT
@FIELDS=COALESCE(@FIELDS, '' '','''')+ ''<td style='' + ''"border:1px solid black;color:white">'' + name + ''</td>''
FROM tempdb.sys.Columns
WHERE object_id=object_id(''tempdb..#FeesCalculation'')
AND name not like ''CustColHTML_ID''
AND name not like ''ItemID''
Is this what you want?
SELECT @FIELDS = (COALESCE(@FIELDS, '' '','''') + ''<td style='' +
''"border:1px solid black;color:white">'' +
(CASE WHEN name = 'ItemDesc' THEN '[Item Description]' ELSE name END) + ''</td>''
)
SELECT REPLACE(@FIELDS,'ItemDesc','Item Description')
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.