I have a field called stock_code, the data in that field, looks like
this
000000851. I need to replace only the first two charachters '00' with
'DR'.
If I use the replace function, it will of course replace every
occurance of 00 which I dont want.
Apart from exporting the data out to excel and changing it there
Thanks
AlanAlan,
Is the field stock_code always 9 chars? If so, you can use the SUBSTRING
function of SQL.
I think
UPDATE TABLE
SET STOCK_CODE = 'DR' + SUBSTRING(STOCK_CODE,3,7)
Should do the trick. Be careful as above statement has no WHERE clause so
this will be done on all products!!!!
Oscar...
"Alan Payne" <Jherek@.bigpond.com> wrote in message
news:4ff57fb9.0402011626.ab0a494@.posting.google.co m...
> First of all I am not familiar with SQL so bear with me.
> I have a field called stock_code, the data in that field, looks like
> this
> 000000851. I need to replace only the first two charachters '00' with
> 'DR'.
> If I use the replace function, it will of course replace every
> occurance of 00 which I dont want.
>
> Apart from exporting the data out to excel and changing it there
> Thanks
> Alan|||Jherek@.bigpond.com (Alan Payne) wrote in message news:<4ff57fb9.0402011626.ab0a494@.posting.google.com>...
> First of all I am not familiar with SQL so bear with me.
> I have a field called stock_code, the data in that field, looks like
> this
> 000000851. I need to replace only the first two charachters '00' with
> 'DR'.
> If I use the replace function, it will of course replace every
> occurance of 00 which I dont want.
>
> Apart from exporting the data out to excel and changing it there
> Thanks
> Alan
update dbo.MyTable
set stock_code = stuff(stock_code, 1, 2, 'DR')
where ...
Simon|||"Simon Hayes" <sql@.hayes.ch> wrote in message
news:60cd0137.0402020218.1a083127@.posting.google.c om...
> Jherek@.bigpond.com (Alan Payne) wrote in message
news:<4ff57fb9.0402011626.ab0a494@.posting.google.com>...
> > First of all I am not familiar with SQL so bear with me.
> > I have a field called stock_code, the data in that field, looks like
> > this
> > 000000851. I need to replace only the first two charachters '00' with
> > 'DR'.
> > If I use the replace function, it will of course replace every
> > occurance of 00 which I dont want.
> > Apart from exporting the data out to excel and changing it there
> > Thanks
> > Alan
> update dbo.MyTable
> set stock_code = stuff(stock_code, 1, 2, 'DR')
> where ...
> Simon
Thank you to both the people who responded.
Alan
No comments:
Post a Comment