|
Comments
|
|
Really good as usual, muy bueno como siempre
|
|
|
Good content. I don't use concatenation that often, so I find this helpful as a refresher as well.
|
|
|
good trick
|
|
Eric Moreau on
10/21/2010
instead of replacing ' ' with ' ', you should have use:
firstname + ' ' + isnull(left(middlename, 1) + ' ', '') + lastname
|
|
|
You can use a Case Statement:
SELECT (RTRIM(dbo.NameHistoryTable.FirstName) +
CASE MiddleInitial
WHEN ' ' THEN ' '
ELSE ' ' + RTRIM(MiddleInitial) + '. '
END
+ RTRIM(dbo.NameHistoryTable.LastName)) AS FullName
FROM dbo.NameHistoryTable
|
|
Yelena Varshal on
10/21/2010
Very good!
|
|
|
Hi There,
Well, instead of replacing double spaces by single space for @contactlist variable, one can do the following:
SELECT @a = @a + FirstName + ' ' +
ISNULL(Left(MiddleName, 1) + ' ', '') +
LastName + ', '
and then you can discard the trailing , from @a and that's it.
You don't have to use replace function at all.
Warm Regards,
Umesh Bhavsar
|
|
|
very interesting
|
|
Jamshid Nouri on
10/21/2010
excellent demo
|
|
|
helpful
|
|
sam_shenouda on
10/22/2010
this is great. I have done at my job and it took a little while to figure it out
|
|
|
Nice video
|
|
Dexter Jones on
10/22/2010
Slick.
Nice tip about initializing the varchar(MAX) variable.
Thanks!
|
|
Lerma Winchell on
10/22/2010
Very nice tip.
|
|
David Stark on
10/22/2010
Cool trick with concatenating strings!
|
|
|
Solution left trailing ,
|
|
Tom Uellner on
10/24/2010
Perhaps it could be a little more concise using COALESCE()?
DECLARE @ContactList VARCHAR(MAX)
SET @ContactList = ''
SELECT TOP 50
@ContactList = @ContactList + FirstName + ' ' + COALESCE(LEFT(MiddleName, 1) + ' ', '') + LastName + ','
FROM Person.Contact
SELECT @ContactList
|
|
|
Good tips.
|
|
|
This would be great for making CSV files too, but you need to remove the trailing comma.
|
|
Daniel Wolford on
10/26/2010
Surprised you didn't mention this trick's usefullness in avoiding a cursor to do the same work, and how much more efficient it is. Also, this trick is proprietary to SQL Server, from what I have read..i.e. Oracle can't do it! :)
|
|
James Millican on
10/28/2010
could have used coalesce
|
|
|
As someone who uses a lot of CTEs, this is gong to come in handy building IN lists to be used in a lower CTE.
|
|
Jason P. Brown on
11/10/2010
Need to bump up the volume and have presenter keep voice dynamics level throughout presentation.
|
|
|
nice job
|
|
|
very good.
|