我有一个拥有超过1500个记录的表,我想将no包含@Cot_NomArr = 'PAGO'的数据插入到另一个表中,而我要插入的记录是表中的变量@Cot_Credit:
ABCOTIZA
-------------------------
Cot_Credit | Cot_NomArr
-------------------------
5459892698 | DEBT
3649949499 | DEBT
6265662645 | PAGO
6265662645 | PAGO
6565626569 | DEBT因此,下面是我的查询:
create table #TESTINT(
    Cre_Numero  varchar(15) 
)
select * from ABCOTIZA
DROP TABLE #TESTINT
/* VARIABLES*/
declare @Cot_Credit varchar(15)
/* CONSTANTES*/
declare @Cot_NomArr varchar(150)
/* DECLARACIÓN DE CONSTANTE*/
select  @Cot_NomArr = 'PAGO'
select @Cot_Credit = isnull(Cot_Credit,''),
       @Cot_NomArr = isnull(Cot_NomArr,'')
      from ABCOTIZA noholdlock  
if not exists (select distinct(Cot_Credit) from ABCOTIZA where Cot_Credit = @Cot_Credit and Cot_NomArr = @Cot_NomArr) begin
    insert into #TESTINT(Cre_Numero)
        values (@Cot_Credit)
end
select * from #TESTINT我想在我的桌子#TESTINT的末尾看起来像:
#TESTINT
----------------
@Cot_Credit
----------------
5459892698
3649949499
6565626569因为那些在'PAGO'中没有Cot_NomArr的
我在使用ASE Sybase
但是不起作用,它没有插入任何数据.请帮忙,
发布于 2020-04-27 00:49:33
这是你想要的吗?
insert into #TESTINT (Cre_Numero)
    select a.Cre_Numero
    from ABCOTIZA a
    where a.Cot_NomArr <> 'Pago';https://stackoverflow.com/questions/61450064
复制相似问题