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.