When I select there is one column to show.
And I have a below example codes
C*12:03:01:01
C*12:03:01:02
C*12:03:06
C*12:109
C*12:110
C*12:111
C*12:23
It should be there is : delimiter.
And when it's sorting it should sort each level
For example first level 12 it's all same so same sorting and second level 03, 03, 23, 109, 110,111 like number and then third ...
So it should show as below
C*12:03:01:01
C*12:03:01:02
C*12:03:06
C*12:23
C*12:109
C*12:110
C*12:111
I have tried delete all character and show only number with below function
CREATE FUNCTION [dbo].[fn_StripCharacters]
(
@String NVARCHAR(MAX),
@MatchExpression VARCHAR(255)
)
RETURNS NVARCHAR(MAX)
AS
BEGIN
SET @MatchExpression = '%['+@MatchExpression+']%'
WHILE PatIndex(@MatchExpression, @String) > 0
SET @String = Stuff(@String, PatIndex(@MatchExpression, @String), 1, '')
RETURN @String
END
When I try
select dbo.fn_StripCharacters(DATA.AlleleName, '^0-9')
from @temp
where CAST(dbo.fn_StripCharacters(DATA.AlleleName, '^0-9') AS INT)
Then It will show
1223
12109
12110
12111
120306
12030101
12030102
So I change my mind each level (Delimited by : ) has only 3 character maximum.
Do you guys know way to make
012:003:001:001
012:003:001:002
012:003:006:000
012:109:000:000
012:110:000:000
012:111:000:000
012:023:000:000
Then If I remove : and sorting maybe it will work.
Do you guys have any better idea for this? Thank you!
In your example, I think you can have
parsename()
do the work for you:Your examples all have four parts, so this should work. Also, the first element looks (from your examples) like it can be sorted alphabetically.