Error run UPDATE SQL Server

Asked

Viewed 202 times

1

When executing the update statement below is occurring the following error. What can be?

Msg 116, Level 16, State 1, Line 3 Only an expression can be specified in the selection list when the subconsultation is not entered with EXISTS

UPDATE EstoqueTarefa 
SET EstTarTitulo = (SELECT CONCAT(EstTarTitulo, '-' ,DATENAME(MONTH,getdate())),'-',DATEPART(YEAR,getdate())) 
where EstTarID = 246 
  • You want to concatenate EstTarTitulo + - + Mês + - + Ano? I think there’s an extra parenthesis after getdate(), that should be at the end.

1 answer

1


The problem is in Subquery, only performs select field1, field2, etc. You do not need to use Select because the GETDATE() function can be invoked without problem.

SET EstTarTitulo = CONCAT(EstTarTitulo, '-' ,DATENAME(MONTH,getdate()),'-',DATEPART(YEAR,getdate()))
  • Gave it all @Claudio Lopes, thanks.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.