New answers tagged syntax
You can't use a variable with DROP LOGIN. To do this you'll need to use dynamic SQL: DECLARE @obso_user VARCHAR(16) SET @obso_user = 'BEN_VA\20362781' DECLARE @sql NVARCHAR(100) SET @sql = N'DROP LOGIN [' + @obso_user + ']' EXEC sp_executesql @sql Put that in a CURSOR to do more than the single login: DECLARE @obso_user VARCHAR(16) DECLARE @sql ...
Here below you have the answer. To highlight the change, I inserted two FirstName as 'not_updated'. Please, see SQL_Fiddle update Table1 join Table2 on Table1.id = Table2.id set Table1.FirstName = 'Temp1' where Table2.CreateTS < '2014-02-08 15:00:00.000'; I hope this helps.
Try: update Table1 t1 set t1.Firstname = 'Temp1' inner join Table2 t2 on t1.Id = t2.Id -- Whatever your PK and FK are here where t1.Firstame = 'xxx' and t2.CreateTS < '2014-02-08 15:00:00.000'
I wouldn't use join for that. Try: UPDATE Table1,Table2 SET Table1.FirstName = 'Temp1' WHERE Table1.FirstName = 'xxx' AND Table1.ID = Table2.ID AND Table2.CreateTS < '2014-02-08 15:00:00.000'
Top 50 recent answers are included