SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


concat string with numeric


concat string with numeric

Author
Message
jbalbo
jbalbo
SSChasing Mays
SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)

Group: General Forum Members
Points: 603 Visits: 668
I know this is pretty basic ...

but how do I concat string and numeric?

I wanted Client.LName + ', ' + Client.FName + ' -' & client.ID as ClientName

where client.id is numeric

Thanks
in advance

Joe
CapnHector
CapnHector
Ten Centuries
Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)Ten Centuries (1.3K reputation)

Group: General Forum Members
Points: 1327 Visits: 1789
You need to convert the numeric value to a text value. http://msdn.microsoft.com/en-us/library/ms187928.aspx Once all the data is strings you can concat to your hearts content.


For faster help in answering any problems Please read How to post data/code on a forum to get the best help - Jeff Moden for the best way to ask your question.

For performance Issues see how we like them posted here: How to Post Performance Problems - Gail Shaw

Need to Split some strings? Jeff Moden's DelimitedSplit8K
Jeff Moden's Cross tab and Pivots Part 1
Jeff Moden's Cross tab and Pivots Part 2
jbalbo
jbalbo
SSChasing Mays
SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)

Group: General Forum Members
Points: 603 Visits: 668
Thanks

SO this works!!!

Client.LName + ', ' + Client.FName + ' -' + cast(client.ID as nvarchar) as ClientName
Sean Lange
Sean Lange
One Orange Chip
One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)One Orange Chip (25K reputation)

Group: General Forum Members
Points: 25781 Visits: 17509
jbalbo (11/14/2012)
Thanks

SO this works!!!

Client.LName + ', ' + Client.FName + ' -' + cast(client.ID as nvarchar) as ClientName


Be very careful about using the default lengths for datatypes. When you don't specify the length you get the default size, and this can vary depending on context. I would add a length for your nvarchar. I don't know what datatype your ID is but 10 should be plenty of room. Make it smaller if you don't need that much length, or longer if needed.


Client.LName + ', ' + Client.FName + ' -' + cast(client.ID as nvarchar(10)) as ClientName



/soapbox on

As a side note, it is often considered poor naming convention to have ID. What happens when you have two tables with a PK named ID? Something like ClientID is probably a better choice. One general rule for databases is that is usually preferred that a column name not change it's name when referenced as a foreign key. For example. If you have an Order table and the PK is ID it gets awfully confusing. You have a column with the same name in two tables but you join those tables on Order.ClientID = Client.ID where Order.ID = 8473. That just makes my head spin. If those same two table were aliased O and C the join becomes very clear (O.ClientID = C.ClientID where O.OrderID = 8473

/soapbox off

_______________________________________________________________

Need help? Help us help you.

Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

Need to split a string? Try Jeff Modens splitter.

Cross Tabs and Pivots, Part 1 – Converting Rows to Columns
Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs
Understanding and Using APPLY (Part 1)
Understanding and Using APPLY (Part 2)
jbalbo
jbalbo
SSChasing Mays
SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)SSChasing Mays (603 reputation)

Group: General Forum Members
Points: 603 Visits: 668
Thx good advice.. have a great day



U7
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search