Sqlserver
 sql >> Database >  >> RDS >> Sqlserver

inserire il record in una tabella copiando una singola riga di una singola colonna da un'altra tabella

Non puoi avere due clausole WHERE in una dichiarazione:

insert into RECEIVE(Aname , Permission)
  select Aname , 'select' 
  from SEND
  WHERE Aname = 'GREAME'   <=== WHERE #1
  where not exists         <=== WHERE #2
    (select *  from RECEIVE where aname = 'GREAME' and Permission = 'select')

Devi cambiare la seconda parte in un AND:

insert into RECEIVE(Aname , Permission)
  select Aname , 'select' 
  from SEND
  WHERE Aname = 'GREAME'  
  AND not exists
    (select *  from RECEIVE where aname = 'GREAME' and Permission = 'select')