Discussion Locked

SQL NText field concatenation?

0 helpful
5 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Is there a way to concatenate 2 NText fields using T-SQL?

I'd like to do sometheing like:
INSERT Table2 (SELECT NText1 + NText2 from Table1)

The '+' concatenation operator is disallowed for Text and NText datatypes.

I'm using MS SQL Server7.0

TIA

5 replies

by limbo

Andrew,

Yes there is, use this explicit conversion:

SELECT CAST(NText1 AS VARCHAR(8000)) + CAST(NText2 AS VARCHAR(8000)) FROM TABLE1

If you have concerns about maintaining the datatype outputted the cast as follows

SELECT CAST(CAST(NText1 AS VARCHAR(8000)) + CAST(NText2 AS VARCHAR(8000))AS NTEXT) FROM TABLE1

SQL Server 7 does not support image data types and text datatypes in the fashion you'd expect. Another problem, SQL limits this cast or conversion to 8000 charactersonly.

If this proves too limiting then I'm afraid you may have to use another datatype for your fields.

by andrew

I had thought of this, but I need to handle data beyond 8000 characters.

Thanks anyway.

by limbo

Q: Can MS SQL 7 concatenate nText fields?
A: No. (See above)

Perform your function at the application layer not at the DB layer if you can not alter the datatypes.

This discussion is closed to new replies.