我有两列-名称和ccNumber。我想显示两个列,其中之一被遮盖。
此查询仅显示一列,但我希望显示所有列:
declare @t table (card_no varchar(20))
insert into @t
select ccNUMBER from ccinfo
select 'XXXX-XXXX-XXXX-'+ substring(card_no, 13, 4) as card_no from @t
答案 0 :(得分:0)
检查以下示例。我认为您需要串联列。
create table demo
(
firstName varchar(30),
secondName varchar(30)
);
insert into demo
values
('soumyajit', 'chatterjee'),
('papai', 'chatterjee'),
('virat', 'kohli');
select concat(firstName, ' ', secondName)as Name from demo;
答案 1 :(得分:0)
您也需要获取第二列:
declare @t table (card_no varchar(20), name varchar(64));
insert into @t
select ccNUMBER, name from ccinfo
select 'XXXX-XXXX-XXXX-'+ substring(card_no, 13, 4) as card_no, name from @t
或仅使用原始表:
select 'XXXX-XXXX-XXXX-'+ substring(ccNUMBER, 13, 4) as card_no, name from ccinfo
答案 2 :(得分:0)
您可以在下面尝试
declare @t table (name varchar(100),card_no varchar(20))
insert into @t
select name, ccNUMBER from ccinfo
select name, 'XXXX-XXXX-XXXX-'+ substring(card_no, 13, 4) as card_no from @t