This is my .sql file, it's saved as "Split.sql" and is located in C:\
INSERT Employee (Name)
values ('Roland Eric Real')
SELECT * FROM Employee
GO
select
Name,
-- instead of spaces you can use any delimiter that you have like a comma
-- We replace the delimiter with dot, which is used by the function PARSENAME
PARSENAME( REPLACE(Name, ' ','.') ,3) as LastName,
PARSENAME( REPLACE(Name, ' ','.') ,2) as FirstName,
PARSENAME( REPLACE(Name, ' ','.') ,1) as MiddleName
from Employee
GO
-- If you need to alter the table then
-- Alter the table and add new columns
ALTER TABLE Employee
ADD LastName varchar(50),
FirstName varchar(50),
MiddleName varchar(50)
GO
-- Moving the data from FullName to the new columns
UPDATE Employee SET
LastName = PARSENAME( REPLACE(Name, ' ','.') ,3),
FirstName = PARSENAME( REPLACE(Name, ' ','.') ,2),
MiddleName = PARSENAME( REPLACE(Name, ' ','.') ,1)
GO
SELECT * FROM Employee
GO
-- Now we can drop the old column
ALTER TABLE Employee
DROP COLUMN Name
GO
-- Reclaim space by rebuilt the table
ALTER TABLE Employee REBUILD
GO
SELECT * FROM Employee
GO
I am using windows form in visual studio c#. Basically, when I press a button in windows form, I want it to run that code in sql. Any help would be appreciated, thank you. ^_^