monkey_boys
monkey_boys

Reputation: 7348

how to concatenate string from query sql server 2005 but datatype is integer

(WATCHDOGACIDT.COMASCALEE + WATCHDOGACIDT.COMASCALEV + 
                      WATCHDOGACIDT.COMASCALEM) AS EVM           --not work

(PATIENT_NAME.FIRSTNAME +' '+ PATIENT_NAME.LASTNAME) AS Fullname --work great 

but this code return summary

ex 1 + 2 + 3 i would like return 123 but return 6 thank

Upvotes: 0

Views: 812

Answers (2)

jasonmw
jasonmw

Reputation: 1138

Mitch's answer has the right approach, but in case you don't always know the length of the value you are casting to a varchar you don't need to specify the length. i.e. if one of your numbers was 450 or something, the varchar(1) wouldn't do the trick.

Like this:

CAST(myIntegerVar AS varchar) + ' some text etc'

(CAST(WATCHDOGACIDT.COMASCALEE as varchar) + CAST(WATCHDOGACIDT.COMASCALEV AS varchar) + CAST(WATCHDOGACIDT.COMASCALEM AS varchar) ) AS EVM

Upvotes: 1

Mitch Wheat
Mitch Wheat

Reputation: 300559

Like this:

CAST(myIntegerVar AS varchar(50)) + ' some text etc'

so:

(CAST(WATCHDOGACIDT.COMASCALEE as varchar(1)) + CAST(WATCHDOGACIDT.COMASCALEV AS varchar(1)) + CAST(WATCHDOGACIDT.COMASCALEM AS varchar(1)) ) AS EVM

Upvotes: 4

Related Questions