Hi everyone! Ok so I have 2 columns, one is a Name column, the other is a foreign key. In my Name column, this is the format of all the records in it : number-Name number ranges from like 1 to 1000, is there any way I can basically extract these numbers before each name, insert it into the foreign key column, then remove the number and the hyphen? I think I might need to use a regular expression, but I'm not so good at those. I'm not sure if I explained that right, let me know if you need me to explain more! Thank you.
I would create a Cursor to do it. If you look in SQL help you will find how to create a cursor. A cursor step throw every record, you can then use select SUBSTRING(name,CHARINDEX("-",namecol)) as DBID,namecol from table as a question, then update with update table set IDcol=@dbid where name=@namecol I dont have sql server here so i can not test the above, but something like that should work. Make sure you dont lock the record with the cursor, you can not update a locked record.