Friday, January 31, 2020

SQL SERVER - How to make cumulative sum column

If you need cumulative sum if SQL select, you can use analytical function:
select  cast( mag as int ) as mag, count(*) as count,
sum ( count(*) ) over 
( order by cast( mag as int ) rows between unbounded preceding and current row ) 
as count_cumul
from dso
where
catalog = 'MYDSO'
group by cast( mag as int )
order by cast( mag as int )
Output:
mag         count       count_cumul
----------- ----------- -----------
0           5           5
1           5           10
2           7           17
3           13          30
4           26          56
5           45          101
6           88          189
...

Tuesday, January 14, 2020

C# - How to sort generic list by item value

private List<ConstellationIndex> ConstellationsIndex = new List<ConstellationIndex>();
...
this.ConstellationsIndex.Sort( (x, y) => x.Constellation.CompareTo( y.Constellation ) );

Thursday, January 9, 2020

C# - How to go through files in directory with files copy

DirectoryInfo dir = new DirectoryInfo( this.OverviewMapCopyFromDir );

foreach( FileInfo file in dir.GetFiles( "overview_*.tif" ) ) {
  File.Copy( file.FullName, Path.Combine( m_FullOutputDirectory, file.Name ) );    
}

Friday, January 3, 2020

C# - How to convert first character of string to upper letter

The problem is little complicated, because access to string chars (through indexer) is only read-only.
One way is this:

row.Constellation = arr[2].Trim().ToLower();
char[] ch = row.Constellation.ToCharArray();
ch[0] = char.ToUpper( row.Constellation[0] );
row.Constellation = new string( ch );