Monday, March 19, 2012

I want to add two text columns

Hi all,
I have a two text columns in my table with more than 100,000 rows.
I want to create a third text column with the data from text column 1 + text
column 2.
Is there an easy way to concatinate two text fields?
Thanks
RajuNo, there is no easy way. Why would you want to do this? Is your SQL
statement too long when you list both columns? This seems like a weird
requirement to me. Usually you use separate TEXT columns because you need
them separate. Otherwise, most applications could have just used a single
text column in the first place.
If you have less than 8000 characters in each column, you could use a view,
and say:
SELECT
..,
ConcatenatedColumn = CONVERT(VARCHAR(8000), textCol1)
+ CONVERT(VARCHAR(8000), textCol2)
FROM
..
Then, you don't have to change the underlying table, or any of the
procedures / apps that insert/update the data. (Or, better yet, if you
don't need TEXT, change the columns to VARCHAR.)
Otherwise, the best way would probably be to add the 3rd column, use an
external app to loop through, concatenate, and update the new column, and
then delete the first two columns. (An external app will be much more
friendly with joining the two values than SQL Server will be internally.)
A
"Raju" <npraju1@.hotmail.com> wrote in message
news:%23mM%237ZCAGHA.2040@.TK2MSFTNGP14.phx.gbl...
> Hi all,
> I have a two text columns in my table with more than 100,000 rows.
> I want to create a third text column with the data from text column 1 +
> text
> column 2.
> Is there an easy way to concatinate two text fields?
> Thanks
> Raju
>|||Aaron,
Thank you for your response.
Actually we have legacy application, which has summary in one text column
and description in one text column.
Our new application has only one column, now my job is to get those two
columns into one new column in our new application.
Hope this helps.
BTW
Unfortunately I can't use your solution as both the columns have huge data,
more than 8000 bytes.
Thanks
Raju
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:eWjN6eCAGHA.1256@.TK2MSFTNGP15.phx.gbl...
> No, there is no easy way. Why would you want to do this? Is your SQL
> statement too long when you list both columns? This seems like a weird
> requirement to me. Usually you use separate TEXT columns because you need
> them separate. Otherwise, most applications could have just used a single
> text column in the first place.
> If you have less than 8000 characters in each column, you could use a
view,
> and say:
> SELECT
> ...,
> ConcatenatedColumn = CONVERT(VARCHAR(8000), textCol1)
> + CONVERT(VARCHAR(8000), textCol2)
> FROM
> ...
> Then, you don't have to change the underlying table, or any of the
> procedures / apps that insert/update the data. (Or, better yet, if you
> don't need TEXT, change the columns to VARCHAR.)
> Otherwise, the best way would probably be to add the 3rd column, use an
> external app to loop through, concatenate, and update the new column, and
> then delete the first two columns. (An external app will be much more
> friendly with joining the two values than SQL Server will be internally.)
> A
>
> "Raju" <npraju1@.hotmail.com> wrote in message
> news:%23mM%237ZCAGHA.2040@.TK2MSFTNGP14.phx.gbl...
>

No comments:

Post a Comment