Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Concatenating Error

Author  Topic 

sross81
Posting Yak Master

228 Posts

Posted - 2009-07-29 : 12:42:54
I am trying to concatenate two fields both are integers

e.bp_systolic + '/' + e.bp_diastolic as BP

I get this error:
Msg 245, Level 16, State 1, Line 153
Conversion failed when converting the varchar value '/' to data type int.

I am not really trying to convert anything I just want to put the two numbers together with a "/". Can anyone tell if I am doing something wrong?

Thanks in Advance!
Sherri

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-07-29 : 13:23:34
You need to convert both values to strings before you can concatenate them.

Something like this:

SELECT CONVERT(VARCHAR(50),e.bp_systolic) + '/' + CONVERT(VARCHAR(50),e.bp_diastolic) AS BP

Some days you're the dog, and some days you're the fire hydrant.
Go to Top of Page

sross81
Posting Yak Master

228 Posts

Posted - 2009-07-29 : 13:33:55
Thank you so much for that help that will definitely help me out alot in the future!


quote:
Originally posted by Skorch

You need to convert both values to strings before you can concatenate them.

Something like this:

SELECT CONVERT(VARCHAR(50),e.bp_systolic) + '/' + CONVERT(VARCHAR(50),e.bp_diastolic) AS BP

Some days you're the dog, and some days you're the fire hydrant.



Thanks in Advance!
Sherri
Go to Top of Page

Skorch
Constraint Violating Yak Guru

300 Posts

Posted - 2009-07-29 : 14:26:56
You're welcome :)

Some days you're the dog, and some days you're the fire hydrant.
Go to Top of Page
   

- Advertisement -