October 3, 2008 at 9:04 am
I have to concatenate fields from a table into on huge column in another table. Problem is some of the data from some of the columns are varchar, float and decimals. the original data was imported from Access.
How do I concatenate these fields into one column. Also, if the column is null or empty, I have to insert ' ' as a delimiter.
Sample:
col1,col2,col3,col4 (assuming no data in col3 and col4 is null)
I have to put them together to look like this - note there are 2 delimiters at the end for empty data and a null field:
October 3, 2008 at 9:18 am
The only way to combine all of those types is to get them into a varchar datatype.
The real question is why do you need to combine the columns? I'm going to assume this is for some sort of export to another application, and the file spec is being dictated to you. If so, fine do what you have to do. If this is instead for some sort of database to be used by your company, why combine them? What's the business reason? You should be able to combine them on output to a front end, don't store it that way.
-Luke.
October 3, 2008 at 9:20 am
October 3, 2008 at 9:21 am
You are very right, Luke.
The file is for a client and they
dictate how they want it.
Concatenating numbers and text and delaing with nulls
is crazy.
October 3, 2008 at 9:23 am
When I use CAST it turns a 10 digit phone
number into this - 5.19753e+009.
October 3, 2008 at 9:24 am
October 3, 2008 at 9:27 am
For a 10 digit phone number, I'm guessing it's already a character datatype and not an int so there would be no need to cast it. You can append a character datatype to another one without another explicit cast...
October 3, 2008 at 12:09 pm
The phone number is a float, and when using CAST, it will give you scientific notation.
Try this one:
STR(phone, 10,0)
October 3, 2008 at 12:26 pm
October 3, 2008 at 12:30 pm
I'm actually surprised that the data being in a variety of less than optimal datatypes, like a float for a phone number, isn't causing you issues all over your app. I'd seriously consider using this as a way to talk management into giving you the time and resources to correct it...
Additionally I'd really look at using SSIS or DTS to extract this data as it will be tons easier than having to cast/convert everything into one big long string...
October 3, 2008 at 8:05 pm
Franco_1 (10/3/2008)
I have to concatenate fields from a table into on huge column in another table. Problem is some of the data from some of the columns are varchar, float and decimals. the original data was imported from Access.How do I concatenate these fields into one column. Also, if the column is null or empty, I have to insert ' ' as a delimiter.
Sample:
col1,col2,col3,col4 (assuming no data in col3 and col4 is null)
I have to put them together to look like this - note there are 2 delimiters at the end for empty data and a null field:
Despite it's title, there's a pretty good article on how to do such a thing located at the URL in my signature line below.
--Jeff Moden
Change is inevitable... Change for the better is not.
Viewing 11 posts - 1 through 10 (of 10 total)
You must be logged in to reply to this topic. Login to reply