473,473 Members | 1,814 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Data Manipulation

5 New Member
Hello,

I'm trying to change some data in database and I'm having some problems.
Scenario: Table A has a columnA with some data A123, B456, C789, 12345.
ColumnA
A123
B456
C789
12345

I'm trying to multiply the digits in the column by 2, leaving the letters as is.
The code I'm using is:

UPDATE Table A

SET
CoulmnA= Replace(CoulmnA,Left(CoulmnA,1),' ')
CoulmnA= CAST(CoulmnA AS INT)
CoulmnA= (AcctNo * 2)
CoulmnA= 'A' & AcctNo
WHERE Left(CoulmnA,1) = 'A'

Does any on know of a simple way to do this.
It will be much appreciated
Jun 21 '06 #1
5 1307
CaptainD
135 New Member
I ran this through query analyzer and it worked.

Expand|Select|Wrap|Line Numbers
  1. Declare @tTemp table(iID INT IDENTITY(1,1),
  2. sNumber NVARCHAR(25))
  3.  
  4. Insert into @tTemp (sNumber) Values ('A12345')
  5.  
  6. Update @tTemp set sNumber = LEFT(sNumber, 1)+ '' + Cast(Cast(right(sNumber,LEN(sNumber)-1)as Int)*2 as char(5)) + ''
  7.  
  8. select iID, sNumber from @tTemp
  9. go
  10.  
Jun 21 '06 #2
tr4ga
5 New Member
CaptainD,
Thanks for the reply.
It worked but I need to modify it a bit.
The table has a few hundred rows so
1. I need to feed the values in. (Can I substitute a select clause for A12345 in the code)
2. I need to update the field in the same table

My logic was,
1. scroll through the column,
2. decide if the first digit is a character,
if so take it off, multiply the digit section by to, add it back. there is a character in the f
Jun 22 '06 #3
tr4ga
5 New Member
CaptainD,
Thanks for the reply.
It worked but I need to modify it a bit.
The table has a few hundred rows so
1. I need to feed the values in. (Can I substitute a select clause for A12345 in the code)
2. I need to update the field in the same column and table

My logic was,
1. scroll through the column,
2. decide if the first digit is a character,
if so take it off,
a. multiply the digit section by 2,
b. add the character back.
If not,
a. multiply by 2
3. Update the field.

Sorry for the previous post.
Thanks for any assistance
Jun 22 '06 #4
CaptainD
135 New Member
1. I need to feed the values in. (Can I substitute a select clause for A12345 in the code)
"A12345" is a value in the database table, if there were more rows of data, the sql statement will work the same for each record. I just entered one record into the temp table.

What database are you using? Access, SQL Server???
If it's SQL Server you can use "CASE" for the first character of the record to see if it "is numberic".

ISNUMERIC()
returns 1 when the input expression evaluates to a valid integer, floating point number, money or decimal type; otherwise it returns 0. A return value of 1 guarantees that expression can be converted to one of these numeric types.

Play with it and then post your code, I'll have a look at it.
Jun 22 '06 #5
tr4ga
5 New Member
Captain D
The code worked like a charm.

Update tblDemoTest set AcctNo = LEFT(AcctNo, 1)+ '' + Cast(Cast(right(AcctNo,LEN(AcctNo)-1)as BigInt)*2 as char(15)) + ''

from tblDemoTest

Thanks a million..
Jun 22 '06 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Ferran Foz | last post by:
Hello, I'm using ADODB.Stream to open a binary file on the server and write it down to the browser using Response.BinaryWrite. It's working fine, but i need to make some changes to the binary...
0
by: Dennis McFly | last post by:
Hello, I am running into a problem with an application that doesn't work too well with mutliple rows. Therefore, I need a script that will return a SINGLE row. This is what I'd like to do: I...
1
by: Oded | last post by:
Hello, I'm trying to build a web form which should display a list of DB records and provide edit/insert/delete capabilities. I want to allow client manipulation of the data, including several rows...
2
by: ajay | last post by:
Hi I need to read data from flat files in memory and execute SQL query on the in-memory data. I do not have an option of using a database and I am using c# .Net to build my application. Does...
34
by: Jeff | last post by:
For years I have been using VBA extensively for updating data to tables after processing. By this I mean if I had to do some intensive processing that resulted in data in temp tables, I would have...
3
by: Ben R. | last post by:
Since the original thread is marked as answered, I thought I'd post here to ensure visibility. Hi John and Steven, I'm going the dataset route as access doesn't seem to be too keen on that...
2
by: Mike Cain | last post by:
Hi, The Repeater control seems like exactly what I want to output rows of data from my database. However I need to do some manipulation to the data prior to it being output and I'm not...
5
by: holdingbe | last post by:
Hi all, During the update the views it shows ORA-01732: data manipulation operation not legal on this view error. this view created by only one table. please help me.... Thanks...
13
by: filipo | last post by:
Hello all; I have a .csv file that contains messages exported from one discussion forum that I want to import into another forum (phpBB), but I need to do some data manipulation on the original...
5
by: Spike1980 | last post by:
Hi, I am trying to update a table using cursors... I have a few if clauses... I just put the first if clause and I am trying to update the table, but it gives me an error saying "data...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
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,...
1
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
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

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.