sql server - SqlServer Select Distinct Using Single Column -
i have column contains server in action happened country. so, example, column 'source' contain 'server001[en-us]'. need distinct country codes listed.
id source status ============================== 1 server001[en-us] 3 2 server002[de-ch] 3 3 server005[en-us] 1 4 server001[tr-tr] 3 the ideal query output
en-us de-ch tr-tr can this?
you need play substring , charindex. charindex give location of string within column , substring pretty obvious.
i did not test this, should trick:
select distinct substring(source , charindex('[', source) , charindex(']', source) - charindex('[', source)) );
Comments
Post a Comment