Query in Sql server - sql-server

I have a table which contains data of ledger. it contains field Account name,debit credit.
the data entered in the table at end of month ie. sum of all the days.
Here my problem is that i want to display data of two months i.e current month and the back month. the real problem is that it will be displayed in crosstab
Accname dated debit credit
------- ----- ------ ------
Account name will be in both the months and i want to display one entry from both the month and its corresponding data ie credit and debit field will fill. The query will work on two conditions fields the account name and dated which is to be checked.
Is it possible to use case statement in the query
PLease Help

SQL Server/SQL does not display anything by default. So it doesn't really matter in what form you return the data from your query, as long as it is then visualized the way you want it. Just write your query to return the required data and then care about the visualization.
It might also help us if you told us how you're planning to visualize the data.
To answer your question: Yes, you can use CASE within a query as in
SELECT
CASE WHEN <Condition1> THEN <Value1>
WHEN <Condition2> THEN <Value2>
ELSE <Value3>
END AS <FieldName>

Related

Formatting Excel Table for Percent of total by specific column

I have a table in excel that I'm databasing information in. In this particular excel it is demographic data of students in a certain course across the state of Texas. You can see below that it is filtered by Ethnicity/Hispanic Latino.
Table Screenshot
It's clear to see that the percent row is utter-non sense. What I would really like this last column to do is tell me of what percent all those who took the survey are Hispanic. This becomes tricky because I would like to filter it for all of our "sub-data" as well. So whether I filter it for age, grade, most common language spoken, etc. I'd like to see the percent of that sub data there.
What do I need to do to accomplish this?
Thanks.
Use SUBTOTAL():
=[#Number]/SUBTOTAL(109,[Number])

Calendar with crosstab in jasperreports

I want to create a crosstab in the form of a calendar (Years as first group and months as second group in the columns) with jasperreports. I'm using MySQL database.
1) The first problem is, I'm getting only the months where the measure exists, I want to display all months of the year wether the measure exists for this month or not.
2) Second, I want to have a seperate crosstab for every year in a seperate page.
3) I can't get the months in the right order, they're ordered in alphabetical order.
4) I'm getting a blank first page before the crosstab displays I wanna get rid of. (I'm putting my crosstab in the summary band).
I know these are too much to ask, but I really looked them up deseperatly without any result :'(
For most of this you can fix this in your sql.
1) see Get a list of dates between two dates
3) add a column to your sql and order by it. example SELECT MONTH('2008-02-03'); will return "2"
For #2 you can create a group in Jasper of year (you can create this as a sql column as well or use the java date functions) set the start on new page option for the group. then move your crosstab into the detail band.
i think #2 will fix the #4 problem as well.

ms access conditional formatting statement for recently updated data

Is there a way in MS access 2007 to create a conditional formatting rule that will highlight any field that has been updated in the past 7 days?
Currently I have a rule that highlights any information that is added in the previous week by field value is between Now()-7 and Now(). I'd like to open up the option to modifying old entries that week and have those highlighting as well.
Thanks.
EDIT:
Essentially the database dates back from approximately 6 months. It tracks progress on projects and employees enter task details in a subform of the project.
Date Employee Task
3/14/2012 David Talked to Remou *about ms-access*
8/1/2012 John Solved world hunger
** denotes updated information, and although the task happened on 3/14, I would like to display the changes with conditional formatting. Currently the only thing that would highlight is the 8/1 event.
By far the easiest way is to add an update date and a username. It won't give you a highlighted text difference, but it will be much easier to implement. As an aside, I always add a created timestamp, created user, updated timestamp and updated user to any user maintained tables. It saves so much trouble, because Access does not automatically add this information.

How to arrange a daily time log entry form in Microsoft Access 2007 with Weekdays & Dates in the column headings

The objective is to create a weekly form, in Microsoft Access 2007, that allows employees to select their name from a list, the date of the first day of the week, and then create all daily time longs for the week in single form. The form needs to have a week view like the form (an Excel mockup) shown here:
Once entered, the data is to be written to the Project Time Log table shown here:
When the employee selects the "Week Starting" value, the column headings in the able below need to update. Is this possible? What also has me stumped is how to enter project hours for the week in a single row that will result in creating up to 6 records in my database. Finally, how does one set up validation on the "Week Starting" field so that the employee can only select Mondays?
I guess this is where I admit that I am just getting started with MS Access. However, with some experience in database design and Excel I am finding everything but advanced form building to be fairly straightforward.
So, can someone point me in the right direction? Do I need to use a Pivot Table to make this work? What is a Modal Dialogue? Could it be useful here? Any suggestions would be greatly appreciated.
The easiest way may be to create a table used solely for dataentry that can reside in the front-end for each employee.
DETable
EmployeeID
WeekStarting
ProjectID
Workcode
Mon
Tue
<...>
Sat
You can clear down the table and then append the relevant projectIDs and EmployeeID with a command button or suitable event.
The labels showing Mon, Tue etc can be updated to show the relevant date after WeekStarting is selected.
A suitable set of queries, or a UNION query will allow you to append the data to the main table.

Create day, date, time in DB - Question

Create_date -> Assume it will record as 5/2/2009. For search purposes when searching create date can we search by individual month or year from this or do we need to even record a create_day, create_month, crate_year for this? Once of the search filters for user content will be like example -> "Show content from last 2 weeks, last month, last year, current month only"
create_day -> While we record numeric date, many times for we may need to display the text day (ie: Thursday) to show when the object was created. Like we see on social websites "created on Thursday, Jan 29, 2009 at 3:45pm". To get this output, do we need to record a create_day for all objects / activities or is it calculated on each page load at application level?
create_time -> What time are we storing in DB? User local time or a fixed time? This is a global website. If fixed then let's say I do GMT by default. Then next question is how to display the correct time to a user so it matches his local time? Must factor into calculation that in US time changes twice a year (day light savings). OR, maybe record time always in GMT but display it to users based on their detected time zone,but then that means calculating time from timezone on each page load?
And since I am here, a side Q-> Any difference between lookup and reference table? How to distinguish these two tables -> "Account_status" which has values Active, Confirmed, etc... AND another table "City" which has city names. First table is a system ID table used in back end only. The city table is ID table used by users to select city from. Are these both lookup or reference or same/different?
Create_date You'll usually want to use the DMBS underlying date storage type which stores all pieces of a date (and time if need be, like MySQL datetime). This opens up the ability to use date processing functions within the DBMS. For the filter example, you would calculate what the date was at 2 weeks ago. You may also get have a function to specify such a string in the DBMS. PHP's strotime() allows this.
Create_day The text output is either automatic (MySQL datetime for instance) or it's easy to render whichever piece you need. (PHP date() can do this). It's generally a Good Idea to store a time stamp (datetime) for every record.
Create_time If it's a global app you'll want to use UTC/GMT. Every user will have their offset applied to the times and as well as their form submissions (such as searching). PHP's DateTime objects allow specifying a timezone name as the offset. The user can choose from a list but in it's standard form that's a big list and isn't much towards usability if it doesn't even match their city (http://us.php.net/manual/en/timezones.php). The other option is getting the user's computer's timezone via Javascript.
Lookup Table Yes those are both lookup tables.

Resources