Splitting Full name data to First, Last

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • YamahaB
    New Member
    • Jan 2007
    • 1

    Splitting Full name data to First, Last

    I am trying to figure out how to split a full name field on a space into first name last and update my database, I would prefer to stick to TSQL/SQL if it can be done on SQL Server 2005

    table actors

    actor_id int Unchecked
    actor_name varchar(50) Checked
    rating smallint Checked
    actor_last_name varchar(50) Checked


    DECLARE
    @position int,
    @fullname varchar(50),
    @lastname varchar(50)
    DECLARE
    Names CURSOR FOR
    SELECT actor_name, actor_last_name
    FROM actors;
    OPEN Names;
    FETCH NEXT FROM Names INTO @fullname, @lastname;
    WHILE @@FETCH_STATUS = 0
    BEGIN
    set @position=CHARI NDEX(" ",@fullname ) -- gives Invalid Column name
    if(@position>0)
    begin
    select COUNT(*) from ratings -just needed something here to compile
    end
    FETCH NEXT FROM Names
    END
    CLOSE Names
    DEALLOCATE Names

    SELECT actor_name, actor_last_name
    FROM actors;
    GO
  • iburyak
    Recognized Expert Top Contributor
    • Nov 2006
    • 1016

    #2
    Use single quotes instead of a double.


    [PHP]set @position=CHARI NDEX(' ',@fullname) [/PHP]

    Comment

    Working...