Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Concatenating fields 1

Status
Not open for further replies.

nimishauk

Programmer
Mar 18, 2003
12
ZA
Hi

I'm migrating an access db to SQL and have to concatenate few fields to fit into one field.When I create these insert statements, I need the values to be stored in the database with space between the concatenated fields hence when it gets displayed it show as new line for each field. i.e. I'm concatenating several columns into 1 single field. How can I get each column to appear in a new line.

SELECT 'INSERT INTO Table1 (ID, Title) values
(' + rtrim(convert(char(12),ID)) + ', ''' + rtrim(convert(varchar(8),Code)) + ' - ' + Description + ''' );'
FROM Table2

This returns

INSERT INTO Table1 (ID, Title ) values (1, '2072053 - HELLO WORLD' );
When being displayed I would like the Title to be shown as
2072053 -
HELLO WORLD
rather in one line.

Any ideas?

Ta
Nimisha
 

char(10) and char(13) makes a carriage return which I think is what you want rather than a space, try this.

INSERT INTO Table1 (ID, Title ) values (1, '2072053 -' +char(13) + char(10)+ ' HELLO WORLD' )


Matt

Brighton, UK
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top