I have 2 datefields and i need to count days between these dates. I have a field say kind of category and i need to display these categories as columns and the days are dsplayed as per the category under that particular columns.
O/p
x | y | z
-----------------------
1 | |
| 3 |
12 | |
| | 4
here x, y, z are category in category column and the contents are date 2-date1+1
I was trying to use a query such as,
SELECT CASE WHEN cat='x' THEN ([date2]-[date1]+1) END AS [X_COUNT],CASE WHEN cat='y' THEN ([date2]-[date1]+1) END AS [y_COUNT],CASE WHEN cat='z' THEN ([date2]-[date1]+1( END AS [z_COUNT]
It's giving me error as,
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Description:
An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
You can't use CASE with Access. It doesn't support it. One way to do this is just retrieve the raw values, then use VB or C# in the RowDataBound event of the datacontrol to apply the logic.
victor0282
Member
42 Points
47 Posts
using case with access database : query is giving error
Jan 19, 2009 04:06 PM|LINK
I have 2 datefields and i need to count days between these dates. I have a field say kind of category and i need to display these categories as columns and the days are dsplayed as per the category under that particular columns.
O/p
x | y | z
-----------------------
1 | |
| 3 |
12 | |
| | 4
here x, y, z are category in category column and the contents are date 2-date1+1
I was trying to use a query such as,
SELECT CASE WHEN cat='x' THEN ([date2]-[date1]+1) END AS [X_COUNT],CASE WHEN cat='y' THEN ([date2]-[date1]+1) END AS [y_COUNT],CASE WHEN cat='z' THEN ([date2]-[date1]+1( END AS [z_COUNT]
It's giving me error as,
IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.Exception Details: System.Data.OleDb.OleDbException: IErrorInfo.GetDescription failed with E_FAIL(0x80004005).
Stack Trace:
Access database with ASP.NET -VB.NET
Mikesdotnett...
All-Star
154858 Points
19858 Posts
Moderator
MVP
Re: using case with access database : query is giving error
Jan 19, 2009 06:19 PM|LINK
You can't use CASE with Access. It doesn't support it. One way to do this is just retrieve the raw values, then use VB or C# in the RowDataBound event of the datacontrol to apply the logic.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
hans_v
All-Star
35986 Points
6550 Posts
Re: using case with access database : query is giving error
Jan 19, 2009 10:14 PM|LINK
That's correct, however the equivalent for the SQL Server CASE statement in Access is SWITCH....
-- SQL Server
SELECT CASE
WHEN On=1 THEN 'On'
WHEN On=0 THEN 'Off'
END FROM table
-- or
SELECT CASE On
WHEN 1 THEN 'On'
WHEN 0 THEN 'Off'
END FROM table
Translates in Access to:
SELECT Switch(
On=1,'On',
On=0,'Off'
) FROM table
More information on the differences between Access and SQL Server can be found at:
http://sqlserver2000.databases.aspfaq.com/what-are-the-main-differences-between-access-and-sql-server.html
Mike, maybe a new topic for your website?
Mikesdotnett...
All-Star
154858 Points
19858 Posts
Moderator
MVP
Re: using case with access database : query is giving error
Jan 20, 2009 06:31 AM|LINK
LOL. I think Aaron has done a nice enough job on his site covering this topic.
Well, it's not actually "his" site any more. He sold it a couple of years back...
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
faisalabdul
Member
3 Points
3 Posts
Re: using case with access database : query is giving error
Feb 02, 2012 10:01 AM|LINK
many many thank you .......