0

I want to Combine Height and Height-units together but they are formatted in different data types

I've tried to add them them together, but since they are listed as different data types, I get a completely different result.

SELECT rclm_dem.HEIGHT + rclm_dem.HEIGHT_UNIT,

Results is instead of getting say '56 inches' I get something like '142534'

Height Unit also has codes (1 for inches & 2 for centimeters)

Height Unit is classified as LONG and Height is classified as Decimal

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
SQLNewb
  • 1
  • 2
  • 4
    Tag your question with the database you are using. Sample data and desired results in a text table format also helps. – Gordon Linoff Jul 18 '19 at 18:06
  • You will need to convert the unit codes to strings ("inches" or "centimeters") using a lookup table or a `CASE` statement, and then convert the numeric height value to character data and finally concatenate (not add) the numeric value and the unit string. – rd_nielsen Jul 18 '19 at 18:22
  • Possible duplicate of [SQL, CONVERT, CAST Data Type?](https://stackoverflow.com/questions/44790948/sql-convert-cast-data-type) – sophros Jul 19 '19 at 09:12

1 Answers1

0

The CONVERT option might give you what you are looking for.

SELECT CONVERT(nvarchar,rclm_dem.HEIGHT) + CONVERT(nvarchar,rclm_dem.HEIGHT_UNIT)

With the CAST option

SELECT CONVERT(nvarchar,convert(varchar, cast(56.787534 as money))) 
HereGoes
  • 1,302
  • 1
  • 9
  • 14
  • So I tried the convert option and the result is a table that looks like this Column_name and underneath its gives me numbers such as '56.787534' – SQLNewb Jul 18 '19 at 18:23
  • You can use incorporate the CAST option, see edited answer – HereGoes Jul 18 '19 at 18:34