String manipulation

het onderstaande retourneert de eerste zes characters en de laatste vier characters van een string:

DECLARE @string VARCHAR(20) SELECT @string = 'SearchDatabase.com' SELECT LEFT(@string, 6) AS FirstSix, RIGHT(@string, 4) AS LastFour

Results:

FirstSix LastFour -------- -------- Search .com

Het onderstaande retourneerd een getrimde string:

DECLARE @string VARCHAR(20) SELECT @string = ' SearchDatabase.com ' SELECT LTRIM(@string) AS NoLeadingSpaces, RTRIM(@string) AS NoTrailingSpaces

Results:

NoLeadingSpaces NoTrailingSpaces --------------- ---------------- SearchDatabase.com   SearchDatabase.com

SQL substring function:

DECLARE @string VARCHAR(20) SELECT @string = 'SearchDatabase.com' SELECT SUBSTRING(@string, 7, 8) AS MiddlePortion

Result:

MiddlePortion ------------- Database

Het onderstaande retourneerd ook een substring:

DECLARE @string VARCHAR(20) SELECT @string = 'SearchDatabase.com' SELECT SUBSTRING(@string, CHARINDEX('d', @string), (LEN(@string) - (CHARINDEX('d', @string)-1) - CHARINDEX('.', REVERSE(@string)) ))

Result:

-------------------- Database
 
Het onderstaand retourneert ??
SET CONCAT_NULL_YIELDS_NULL OFF /* declare the variables to hold the old and new company names */ DECLARE @comp_name VARCHAR(75), @newcomp_name VARCHAR(75) SELECT @comp_name = ' woderful world, inc. ' -- upper case each word after a space SELECT @comp_name = LTRIM(RTRIM(@comp_name)) BEGIN WHILE CHARINDEX(' ', @comp_name)<> 0 BEGIN SELECT @newComp_name = @newComp_name + UPPER(LEFT(@comp_name, 1)) + LOWER(SUBSTRING(@Comp_name, 2, (CHARINDEX(' ', @Comp_name)-1))) SELECT @comp_name = SUBSTRING(@comp_name, (CHARINDEX(' ', @comp_name) + 1), (LEN(@comp_name) - CHARINDEX(' ', @comp_name))) END -- Add the last piece (not containing spaces): SELECT @NewComp_Name = @NewComp_Name + UPPER(LEFT(@comp_name, 1)) + LOWER(SUBSTRING(@comp_name, 2, LEN(@comp_name) - 1)) END SELECT @NewComp_Name AS UpperCasedName

Result:

UpperCasedName ------------------------ Woderful World, Inc.

{{opmerking.Naam}}:

{{opmerking.OpmerkingText}}

            

Saving your comment....

Naam is verplicht!
Email is verplicht!
Opmerking is verplicht!