title: SQL Server: How to update table based on subquery in where clause?
body: <p>I have a table (with data) like this:</p>
  
  <pre><code>SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  SET ANSI_PADDING ON
  GO
  CREATE TABLE [dbo].[lTab](
      [log_id] [int] IDENTITY(1,1) NOT NULL,
      [JobName] [nvarchar](40) NULL,
      [startTime] [datetime] NULL,
      [endTime] [datetime] NULL,
      [BatchId] [int] NULL,
      [status] [varchar](10) NULL,
      [messag] [varchar](255) NULL
  ) ON [PRIMARY]
  GO
  SET ANSI_PADDING OFF
  GO
  SET IDENTITY_INSERT [dbo].[lTab] ON
  INSERT [dbo].[lTab] ([log_id], [JobName], [startTime], [endTime], [BatchId], [status], [messag]) VALUES (1, N'Job1', CAST(0x00009EB700FBF56F AS DateTime), NULL, 2, N'START', N'Test')
  INSERT [dbo].[lTab] ([log_id], [JobName], [startTime], [endTime], [BatchId], [status], [messag]) VALUES (2, N'Job2', NULL, CAST(0x00009EB700FBF975 AS DateTime), 2, N'START', N'Test')
  INSERT [dbo].[lTab] ([log_id], [JobName], [startTime], [endTime], [BatchId], [status], [messag]) VALUES (3, N'Job3', CAST(0x00009EB700FC287F AS DateTime), NULL, 2, N'START', N'Test')
  INSERT [dbo].[lTab] ([log_id], [JobName], [startTime], [endTime], [BatchId], [status], [messag]) VALUES (4, N'Job3', NULL, CAST(0x00009EB700FC2CC6 AS DateTime), 2, N'END', N'Test')
  SET IDENTITY_INSERT [dbo].[lTab] OFF
  </code></pre>
  
  <p>I'm trying to update endTime based on Jobname and max(log_id). </p>
  
  <pre><code>DECLARE @Jname VARCHAR(10)
  SET @Jname = 'Job3'
  
  UPDATE lTab
  SET endTime = GETDATE() 
  WHERE log_id = (SELECT JobName, MAX(log_id) AS log_id FROM dbo.lTab WHERE jobname = @Jname GROUP BY JobName)
  </code></pre>
  
  <p>I get an error</p>
  
  <pre><code>sg 116, Level 16, State 1, Line 6
  Only one expression can be specified in the select list when the subquery is not introduced with EXISTS.
  </code></pre>
  
  <p>How to get this work?</p>