all groups > sql server programming > september 2004 >
You're in the

sql server programming

group:

truncate existing values and insert into another column



truncate existing values and insert into another column pk
9/11/2004 11:11:02 PM
sql server programming: Table_A, Field_1 (varchar, 15), Field_2 (varchar, 15, null possible)

sample data for Field_1 :

aa6xxxxxxxxxxxx (len is 15char)
aa8xxxxxxxxxxxx (len is 15char)

If 3rd char is 6, truncate the data, keep only the 1st 6 char from the
right, and insert this truncated data into Field_2

If 3rd char is 8, truncate the data, keep only the 1st 8 char from the
right, and insert this truncated data into Field_2

No update or changes to the existing data values in Field_1

Any idea how ? (Update Table_A..Set Field_2 ....where Field_1... ?? )


Many 10x !

Re: truncate existing values and insert into another column Wayne Snyder
9/12/2004 8:44:09 AM
something like
update table_a
set field_2 =
case substring(Field_1,3,1)
When '6' then Right(Field_1, 6)
When '8' then right(Field_1,8)
end
where substring(field_1,3,1) in ('6','8')

IF the first two values really are know ( ie aa) the where clause would be
faster to be
where field_1 like 'aa[68]%'



--
Wayne Snyder, MCDBA, SQL Server MVP
Mariner, Charlotte, NC
www.mariner-usa.com
(Please respond only to the newsgroups.)

I support the Professional Association of SQL Server (PASS) and it's
community of SQL Server professionals.
www.sqlpass.org

[quoted text, click to view]

Re: truncate existing values and insert into another column Uri Dimant
9/12/2004 9:28:59 AM
PK,
Substring and REPLACE functions you have to look at

[quoted text, click to view]

AddThis Social Bookmark Button