Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Add data in column

Author  Topic 

keesvo
Starting Member

10 Posts

Posted - 2011-11-01 : 10:51:29
Hello everyone,

I have a table with different columns.
In one specific column i want to add data.
This data is split into 2 parts.
The first part is a static text and
the second part is the value of another column in the same table.
Can someone help me ? Thank you in advance.

THIS IS THE MEANING OF IT:

TABLE : ITEMS

BEFORE QUERY

ID ITEMCODE DESCRIPTION PACKAGE
1 PRODUCT_A THIS IS A TESTPRODUCT PER 100
2 PRODUCT_B THIS IS A SECOND TESTPRODUCT PER 50
3 PRODUCT_C THIS IS A THIRD TESTPRODUCT PER 1000
-------------------------------------------------------------------

AFTER QUERY

ID ITEMCODE DESCRIPTION PACKAGE
1 PRODUCT_A THIS IS A TESTPRODUCT PACKAGED PER 100 PER 100
2 PRODUCT_B THIS IS A TESTPRODUCT 2 PACKAGED PER 50 PER 50
3 PRODUCT_C THIS IS A TESTPRODUCT 3 PACKAGED PER 1000 PER 1000

"PACKAGED" IS THE STATIC TEXT I WANT TO ADD
THE SECOND PART IS THE DATA FROM THE COLUMN PACKAGE

nigelrivett
Master Smack Fu Yak Hacker

3385 Posts

Posted - 2011-11-01 : 11:04:40
Not sure which text is in which column but maybe

update tbl
set DESCRIPTION = DESCRIPTION + ' PACKAGED ' + Package

==========================================
Cursors are useful if you don't know sql.
SSIS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

keesvo
Starting Member

10 Posts

Posted - 2011-11-01 : 11:17:18
Thank you.
But when I'm executing the query i get the following error:

String or binary data would be truncated.
The statement has been terminated.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-01 : 11:45:57
quote:
Originally posted by keesvo

Thank you.
But when I'm executing the query i get the following error:

String or binary data would be truncated.
The statement has been terminated.



thats because you DESCRIPTION field doesnt have required length to hold value. Increase length of field using ALTER TABLE.. ALTER COLUMN... and then do the update

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -