Thanks Dev, like this? I added Print statements for the variables. I do not understand the purpose of @DELIMITER or have never seen WHEN used in SQL statements. Nevertheless....see below debug and result.
EXECUTED:
USE Northwind
GO
DECLARE @DELIMITER AS VARCHAR(200)
DECLARE @INSERT_PART AS VARCHAR(2000)
SET @DELIMITER = 'ZZZYYYXXX'
SET @INSERT_PART = 'WHEN EMPLOYEEID < 5' + @DELIMITER + 'INTO EMPLOYEES1 (LASTNAME, FIRSTNAME
VALUES (LASTNAME, FIRSTNAME)' + @DELIMITER + 'WHEN EMPLOYEEID >4' + @DELIMITER + 'INTO EMPLOYEES2 (LASTNAME, FIRSTNAME) VALUES (LASTNAME, FIRSTNAME)'
PRINT @DELIMITER --debug
PRINT @INSERT_PART --debug
EXEC SP_MULTI_INSERTS 'SELECT EMPLOYEEID, LASTNAME, FIRSTNAME FROM EMPLOYEES', @INSERT_PART, @DELIMITER, ''
RESULT:
ZZZYYYXXX
WHEN EMPLOYEEID < 5ZZZYYYXXXINTO EMPLOYEES1 (LASTNAME, FIRSTNAME
VALUES (LASTNAME, FIRSTNAME)ZZZYYYXXXWHEN EMPLOYEEID >4ZZZYYYXXXINTO EMPLOYEES2 (LASTNAME, FIRSTNAME) VALUES (LASTNAME, FIRSTNAME)
Msg 156, Level 15, State 1, Line 2
Incorrect syntax near the keyword 'SELECT'.