Results 1 to 3 of 3

Thread: Please help... TSQL syntax

  1. #1
    Laura Guest

    Please help... TSQL syntax

    Hi,

    I am trying to break up a column "name" into 2 columns "first name" and "last name". The name colum is currently "lastname, firstname". Is there an easy way to do this in SQL 6.5?

    I tried this (below), but I get errors saying the charindex function requires 2 arguments...

    lastname = select substring( colname , 1, charindex(',', colname,1) -1 ) firstname = select ltrim(substring(colname,charindex(',', colname,1) + 1, len(colname)- len(substring( colname, 1, charindex(',', colname,1) -1 ))))

    Thanks.


  2. #2
    tim wilkinson Guest

    Please help... TSQL syntax (reply)

    yes charindex does require 2 args. you've got an extra ",1" as a third parameter.

    select lastname = substring(colname , 1, charindex(',', colname ) -1 )

    select firstname = ltrim(substring(colname,charindex(',', colname ) + 1,
    len(colname)- len(substring( colname, 1, charindex(',', colname) -1 ))))



    ------------
    Laura at 7/5/00 11:08:28 AM

    Hi,

    I am trying to break up a column "name" into 2 columns "first name" and "last name". The name colum is currently "lastname, firstname". Is there an easy way to do this in SQL 6.5?

    I tried this (below), but I get errors saying the charindex function requires 2 arguments...

    lastname = select substring( colname , 1, charindex(',', colname,1) -1 ) firstname = select ltrim(substring(colname,charindex(',', colname,1) + 1, len(colname)- len(substring( colname, 1, charindex(',', colname,1) -1 ))))

    Thanks.


  3. #3
    Sonya A. McNeal Guest

    Please help... TSQL syntax (reply)

    Laura,

    I have a question, or rather need some assistance. I wrote
    this script and looking for some suggestions. Could you look at it?
    The logic behind is: it is suppose to search through the tables of a database
    and find a specific column, for instance Facility is the name of the column and update that column field. But I am having problems with updating the field. Can you by chance help?

    Sonya

    Declare @Tablename char(30), @UpdateColumn char (200)

    Declare curTable Scroll Cursor For

    Select tableobj.Name
    From sysobjects tableobj, syscolumns col
    Where tableobj.Type = 'U' and tableobj.id = col.id
    and Col.Name = 'Facility'

    /*For Update of Name*/

    Open curTable

    Fetch Next From curTable into @Tablename

    While @@Fetch_Status = 0

    Begin
    /*Select @UpdateColumn = "Update" + @Tablename + " Set Facility ='W'"
    Exec (@UpdateColumn)*/

    /*EXEC ('Update' + @Tablename + 'Set Facility = W&#39*/

    Update tableobj.Name
    Set Facility ='W'
    Fetch Next From curTable into @Tablename
    End

    Close curTable
    Deallocate curTable




    ------------
    Laura at 7/5/00 11:08:28 AM

    Hi,

    I am trying to break up a column "name" into 2 columns "first name" and "last name". The name colum is currently "lastname, firstname". Is there an easy way to do this in SQL 6.5?

    I tried this (below), but I get errors saying the charindex function requires 2 arguments...

    lastname = select substring( colname , 1, charindex(',', colname,1) -1 ) firstname = select ltrim(substring(colname,charindex(',', colname,1) + 1, len(colname)- len(substring( colname, 1, charindex(',', colname,1) -1 ))))

    Thanks.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •