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 |
|
rowter
Yak Posting Veteran
76 Posts |
Posted - 2009-09-29 : 19:50:57
|
| Hi,I have lastname and firstname fields.i want to concatenate lastname and firstname fields into one field.i wanto to have a fixed length for lastname field. It should be 10 characters long then a space and then the firstname.Is there any query to concatenate this way?Thanks in advance |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-29 : 21:31:12
|
[code]left(isnull(lastname, '') + space(11), 11) + isnull(firstname, '')[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
johnconstraint
Starting Member
23 Posts |
Posted - 2009-09-29 : 21:34:36
|
| SELECT CAST (LastName AS CHAR(10)) + ' ' + FirstName as 'Name' FROM tablename |
 |
|
|
rowter
Yak Posting Veteran
76 Posts |
Posted - 2009-09-30 : 09:36:58
|
| Thanks guys for your answers.For some reason, the second field that is concatenating is not lining up.Is there any way yo ucan specify that the second field shuld start ata particular position? say 20Thanks in Advance |
 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-09-30 : 10:04:34
|
left(isnull(lastname, '') + space(20), 19) + isnull(firstname, '') KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
rowter
Yak Posting Veteran
76 Posts |
Posted - 2009-09-30 : 17:29:07
|
| In addition to the query, using Courier font on the text (.Net side) solved the problem.Thaks |
 |
|
|
|
|
|
|
|