unote 書けば書くほどに

20230112

public void Count()
{
RTN = "DEPT_BK";

DataTable dt = new DataTable();

//全件数
strSQL = "select count(*) from " + RTN; ;
dt = DBA(strSQL); //SQL実行
Console.WriteLine(RTN + " 全" + dt.Rows[0][0] + "行\r\n");

//カラムごとの件数
int num = 1;

switch (num)
{
case 1:

col1 = "DEPTNO";

strSQL = "select count(" + col1 + ")" + " from " + RTN;
dt = DBA(strSQL); //SQL実行
Console.WriteLine(col1 + ":" + dt.Rows[0][0] + "行\r\n");

break;

case 2:

col1 = "DEPTNO";
col2 = "DNAME";

strSQL = "select count(" + col1 + ")," +
"count(" + col2 + ")" +
" from " + RTN; ;

dt = DBA(strSQL); //SQL実行
Console.WriteLine(col1 + ":" + dt.Rows[0][0] + "行\r\n");
Console.WriteLine(col2 + ":" + dt.Rows[0][1] + "行\r\n");

break;

case 3:

col1 = "DEPTNO";
col2 = "DNAME";
col3 = "KOUSHINBI";

strSQL = "select count(" + col1 + ")," +
"count(" + col2 + ")," +
"count(" + col3 + ")" +
" from " + RTN;

dt = DBA(strSQL); //SQL実行
Console.WriteLine(col1 + ":" + dt.Rows[0][0] + "行\r\n");
Console.WriteLine(col2 + ":" + dt.Rows[0][1] + "行\r\n");
Console.WriteLine(col3 + ":" + dt.Rows[0][2] + "行\r\n");

break;

case 4:

col1 = "DEPTNO";
col2 = "DNAME";
col3 = "KOUSHINBI";
col4 = "KOUSHINBI";

strSQL = "select count(" + col1 + ")," +
"count(" + col2 + ")," +
"count(" + col3 + ")," +
"count(" + col4 + ")" +
" from " + RTN;

dt = DBA(strSQL); //SQL実行
Console.WriteLine(col1 + ":" + dt.Rows[0][0] + "行\r\n");
Console.WriteLine(col2 + ":" + dt.Rows[0][1] + "行\r\n");
Console.WriteLine(col3 + ":" + dt.Rows[0][2] + "行\r\n");
Console.WriteLine(col4 + ":" + dt.Rows[0][3] + "行\r\n");

break;

case 5:

col1 = "DEPTNO";
col2 = "DNAME";
col3 = "KOUSHINBI";
col4 = "KOUSHINBI";
col5 = "KOUSHINBI";

strSQL = "select count(" + col1 + ")," +
"count(" + col2 + ")," +
"count(" + col3 + ")," +
"count(" + col4 + ")," +
"count(" + col5 + ")" +

" from " + RTN;

dt = DBA(strSQL); //SQL実行
Console.WriteLine(col1 + ":" + dt.Rows[0][0] + "行\r\n");
Console.WriteLine(col2 + ":" + dt.Rows[0][1] + "行\r\n");
Console.WriteLine(col3 + ":" + dt.Rows[0][2] + "行\r\n");
Console.WriteLine(col4 + ":" + dt.Rows[0][2] + "行\r\n");
Console.WriteLine(col5 + ":" + dt.Rows[0][2] + "行\r\n");

break;

case 6:

col1 = "DEPTNO";
col2 = "DNAME";
col3 = "KOUSHINBI";
col4 = "KOUSHINBI";
col5 = "KOUSHINBI";
col6 = "KOUSHINBI";

strSQL = "select count(" + col1 + ")," +
"count(" + col2 + ")," +
"count(" + col3 + ")," +
"count(" + col4 + ")," +
"count(" + col5 + ")" +
"count(" + col6 + ")" +
" from " + RTN;

dt = DBA(strSQL); //SQL実行
Console.WriteLine(col1 + ":" + dt.Rows[0][0] + "行\r\n");
Console.WriteLine(col2 + ":" + dt.Rows[0][1] + "行\r\n");
Console.WriteLine(col3 + ":" + dt.Rows[0][2] + "行\r\n");
Console.WriteLine(col4 + ":" + dt.Rows[0][2] + "行\r\n");
Console.WriteLine(col5 + ":" + dt.Rows[0][2] + "行\r\n");
Console.WriteLine(col6 + ":" + dt.Rows[0][2] + "行\r\n");

break;

}
}