您只需要在结果末尾连接您的字符串:
添加:
+ 'TEXT'
sql命令将是
SqlCommand command = new SqlCommand("SELECT PID = RIGHT(REPLICATE('0',8) + CAST(PID AS VARCHAR(8)),8) + 'TEXT' FROM dbo.MDRMASTER WHERE PARENTPID = @PARENTPID",con);
Based on your Edit I think you only want the TEXT appended to the final record. If so, then you could do the following:
create table temp
(
field varchar(10)
)
insert into temp values ('12345678')
insert into temp values ('23456789')
insert into temp values ('34567890')
insert into temp values ('45678901')
insert into temp values ('56789012')
select field
from temp
WHERE field != (SELECT Max(field) from temp)
UNION
select field + 'TEXT'
from temp
WHERE field = (SELECT Max(field) from temp)
drop table temp
If you just need the TEXT as the last row then you would do:
create table temp
(
field varchar(10)
)
insert into temp values ('12345678')
insert into temp values ('23456789')
insert into temp values ('34567890')
insert into temp values ('45678901')
insert into temp values ('56789012')
select field
from temp
UNION
select 'TEXT'
drop table temp
Your SQLCommand would be
SqlCommand command
= new SqlCommand("SELECT PID = RIGHT(REPLICATE('0',8) + CAST(PID AS VARCHAR(8)),8)
FROM dbo.MDRMASTER
WHERE PARENTPID = @PARENTPID
UNION
SELECT 'TEXT'",con);