We're using SQL Server 2008 R2. I inherited an automated process that sends data to a third-party outside vendor via an interface and the data is generated through a SQL query. I need to update the query and provide an unique identifier by concatenating three fields: id, package_size, and package_unit.
The resulting column needs to be id + package_size + package_unit
Some sample data:
I've used CONCAT and CAST to create the following code:
which results in the following:
Unfortunately, there are a lot of fields which are not populated so I will have to come up with something for the NULL values.
What I would like to be able to do is to format the package_size field better. So if the package size was 4.000, it would display as 4. If the package_size was 0.250, it would display as 025, etc.
Specifically,
I can be okay with keeping the trailing zeros (4000 instead of 4) but I really need to get rid of the decimal point and keeping the leading zero if at all possible.
Any suggestions?
id is numeric(18,0)
package_size is numeric(12,3)
package_unit is varchar(254)
The resulting column needs to be id + package_size + package_unit
Some sample data:
Code:
id package_size package_unit
97716 NULL mL
106724 4.000 mL
NULL NULL EACH
121161 1.000 EACH
2508 0.250 EACH
10580 11.250 mL
I've used CONCAT and CAST to create the following code:
Code:
CONCAT((CAST(id AS VARCHAR(15))), (CONCAT((CAST(package_size AS VARCHAR(15))),(package_unit))))
which results in the following:
Code:
97716mL
1067244.000mL
EACH
1211611.00EACH
25080.250EACH
1058011.250mL
Unfortunately, there are a lot of fields which are not populated so I will have to come up with something for the NULL values.
What I would like to be able to do is to format the package_size field better. So if the package size was 4.000, it would display as 4. If the package_size was 0.250, it would display as 025, etc.
Specifically,
Code:
1067244.000mL would be 1067244mL
1211611.00EACH 1211611EACH
25080.250EACH 2508025EACH
1058011.250mL 105801125mL
I can be okay with keeping the trailing zeros (4000 instead of 4) but I really need to get rid of the decimal point and keeping the leading zero if at all possible.
Any suggestions?