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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

concatenating null & non-null values

Status
Not open for further replies.

sivi

IS-IT--Management
Nov 27, 2002
27
GB
I AM TRYING TO CONCATENATE 2 FIELDS, ONE IS HAVING DATA IN IT AND THE OTHER ONE IS 'NULL'. IN THE OUTPUT FIELD I WANT TO REPLACE 'NULL' WITH '0000'.

DATAFIELD 1 = '30001237'

DATAFIELD 2 = 'NULL'

I WANT TO CONCATENATE THE ABOVE 2 AND GET '300012370000'

PLEASE COULD SOMEONE HELP ME WITH THIS. ANY HELP WILL BE GREATLY APPRECIATED.

SIVI
 
Hi,

How about this:

SET NewDataField = DataField1 + ISNULL(Datafield2,'0000')

One of two things will happen:

1. If Datafield1 = '30001237' and Datafield2 = '1234' (ie is not null) then NewDataField will be '300012371234'

2. If DataField2 is null, NewDataField will be set to '300012370000'

Hope this helps

Maria
 
Maria

Thanks for this. It worked for fine

Sivi
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top