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.
Author |
Topic |
mikeallenbrown
Yak Posting Veteran
72 Posts |
Posted - 2013-05-28 : 13:49:21
|
I want to automatically combine two columns into one.MRNum - varchar(30)ClientID - intI created a new column (UniqueName) and tried this computed column formula: ([MRNum]+[ClientID]) ....didn't work.So if MRnum is: 22-123 and ClientID is: 5010 I want UniqueName to automatically populate with 22-1235010-MikeMike Brown |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-05-28 : 14:01:43
|
you'll need to explicitly convert the datatype e.g. MRNum + Convert(varchar,ClientID)Else it will throw conversion errorCheersMIK |
 |
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2013-05-28 : 14:29:43
|
quote: Originally posted by MIK_2008 you'll need to explicitly convert the datatype e.g. MRNum + Convert(varchar,ClientID)Else it will throw conversion errorCheersMIK
though it may not affect in this case, always make it a point to specify a length while casting to varcharsee reason herehttp://visakhm.blogspot.in/2010/02/importance-of-specifying-length-in.html------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
djj55
Constraint Violating Yak Guru
352 Posts |
Posted - 2013-05-28 : 14:30:56
|
To add to what MIK said. SQL tries to convert the equation to all the same data types based on a hiearchy. INT is before VARCHAR so the need for the explicit convertion.djj |
 |
|
mikeallenbrown
Yak Posting Veteran
72 Posts |
Posted - 2013-05-29 : 11:25:11
|
Thank you all! ....MIK's answer was spot on!-MikeMike Brown |
 |
|
MIK_2008
Master Smack Fu Yak Hacker
1054 Posts |
Posted - 2013-05-29 : 12:23:01
|
quote: Originally posted by mikeallenbrown Thank you all! ....MIK's answer was spot on!-MikeMike Brown
You're welcome! Though, I'ven't specified the length (since ClientID is INT) but as Visakh pointed it out, it should be a considering factor. :)CheersMIK |
 |
|
|
|
|