473,405 Members | 2,154 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

Changing Data in SQL

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
Jul 20 '05 #1
3 2245
Alan,

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" <Jh****@bigpond.com> wrote in message
news:4f*************************@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

Jul 20 '05 #2
Jh****@bigpond.com (Alan Payne) wrote in message news:<4f*************************@posting.google.c om>...
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
Jul 20 '05 #3

"Simon Hayes" <sq*@hayes.ch> wrote in message
news:60**************************@posting.google.c om...
Jh****@bigpond.com (Alan Payne) wrote in message

news:<4f*************************@posting.google.c om>...
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
Jul 20 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: z0ink | last post by:
I am working on a small graphing application. In the process of graphing I use 3 seperate scripts for getting the job done. The first is the page that the use sees and selects all the data from. ...
5
by: Eternally | last post by:
Hey folks, To me, this sounds like a crazy question, but I'll throw it out there anyway. Is it possible to change a variables data type half way through a running program? If so, how? ...
7
by: Stefan Finzel | last post by:
Hi, is there a way to change the display property on Windows Mobile 2003 SE Mobile/Pocket Internet Explorer? See following example. Please note: visibilty property has the same problem. Is...
13
by: Peter | last post by:
Can anyone tell me how to change the data type of a field in a table created with a make table query? The field is a binary and must be changed to text. alternately does anyone know how to specify...
10
by: Marizel | last post by:
I'm not sure there's an easy solution to this, but thought I'd ask. I often find myself with a query which I'd like to reuse, but with a different datasource. These datasources generally have...
1
by: Rolln_Thndr | last post by:
I'm vey new to network programing and have a few rather fundemental questions. I'm creating a very basic UDP proxy server and having a few issues regarding the sockets. Is it possible to change...
4
by: Good Man | last post by:
Hi there I have a database with about 20 or so tables, maybe a few thousand rows in each. I am starting to do more complex things with my insertions etc, and I want to start to use...
32
by: deko | last post by:
I have a popup form with a textbox that is bound to a memo field. I've been warned about memo fields so I'm wondering if I should use this code. Is there any risk with changing the form's...
4
by: andychambers2002 | last post by:
I'm working on a "TempFile" class that stores the data in memory until it gets larger than a specified threshold (as per PEP 42). Whilst trying to implement it, I've come across some strange...
4
by: John Kotuby | last post by:
Hi all, I have a simple user-form which accepts contact and profile information for the user to edit and save. All the textboxes are working fine and displaying the expected data, both when the...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.