1. SUBSTRING
SELECT SUBSTRING(em_emplname, 1, NULLIF(CHARINDEX(' ', em_emplname) - 1, -1)) AS [FirstName],
SUBSTRING(em_emplname, CHARINDEX(' ', em_emplname) + 1, LEN(em_emplname)) AS [LastName] from Master_Employee where em_emplcode=20936
2. PARSENAME
SELECT PARSENAME(REPLACE(em_emplname, ' ', '.'), 2) AS FirstName , PARSENAME(REPLACE(em_emplname, ' ', '.'), 1) AS LastName from Master_Employee where em_emplcode=20936
2. PARSENAME
SELECT PARSENAME(REPLACE(em_emplname, ' ', '.'), 2) AS FirstName , PARSENAME(REPLACE(em_emplname, ' ', '.'), 1) AS LastName from Master_Employee where em_emplcode=20936
thanks master, kalau pakai parsename uda bnr ambil kata kedua saja (mengabaikan kata selanjutnya) tapi kok ada yang terambil di kata ketiga dan ada yang null
ReplyDeletemohon pencerahannya master