I've completely confused my self here, I'm probably coming at it from the wrong angle. I'm trying to update 1 table from another.
Table SMS contains SMS_ID, SMS_Number, SMS_Message, Emp_Name, Emp_ID & Processed.
Table Employees contains Emp_ID, Emp_FName, Emp_SName & Emp_CellNumber.
I'm trying to update the SMS table with Emp_Name & Emp_ID where SMS_Number matches Emp_CellNumber where processed is false.
The (non working) code I have at the moment is:
BEGIN DECLARE @Emp_ID INT DECLARE @Emp_Name NVARCHAR(50) IF EXISTS (SELECT 1 @Emp_ID = Emp_ID, (Emp_FName + ' ' + Emp_SName) As @Emp_Name = Emp_Name FROM Employees WHERE Status = 'Live' AND REPLACE(Emp_CellNumber, ' ', '') LIKE '%123456789') BEGIN INSERT INTO SMS (Emp_ID, Emp_Name) VALUES (@Emp_ID, @Emp_Name) WHERE Processed = 'False' END END
Any pointers as to where I've gone wrong or a better way to achieve this please?