Reputation: 35
I want replace null value with 0 and if not null i want to count the data ??
sql = "SELECT b.start,COUNT(a.resourceid) " +
"FROM t1 b,agentconnectiondetail a "+
"WHERE TO_CHAR(a.startdatetime,'%R') >= TO_CHAR(b.start,'%R') AND TO_CHAR(a.enddatetime,'%R') <= TO_CHAR(b.finish,'%R') " +
"AND a.resourceid = '"+dr[1].ToString()+"'" +
"GROUP BY 1 ORDER BY 1";
that query output is null
what must I do ??
Upvotes: 2
Views: 8507
Reputation: 38
Are Start and finish both datetime datatypes ? If they are DATE then %R (HH:MM) is probably meaningless.
If they are Datetime then why not
SELECT b.start,COUNT(a.resourceid) " +
"FROM t1 b,agentconnectiondetail a "+
"WHERE startdatetime >= b.start AND a.enddatetime <= b.finish" +
"AND a.resourceid = '"+dr[1].ToString()+"'" +
"GROUP BY 1 ORDER BY 1";
If start and finish are dates then you can always extend() to be the same startdatetime and enddatetime
Upvotes: 0
Reputation: 54302
At first you should create simple query with simple db table, some values and requested result that clearly shows your problem.
Part 1: I want replace null value with 0
To change NULL into some value you can use NVL()
function. Documentation says: The NVL expression returns different results, depending on whether its first argument evaluates to NULL.
Examples:
SELECT fld, NVL(fld, 0) FROM ...
Part 2: and if not null i want to count the data
SELECT COUNT(*) FROM ... WHERE fld IS NOT NULL
Upvotes: 8