No of days in a month in Query designer
Hi
I have Calender Year/Month (0CALMONTH) in the row of query, I need to show no of days in that month, how can I do this in Query designer
Hi,
If the user requirment is to select a single month for analysis then you could possibly use a formula variable that is populated as a user exit to return the number of days in the month selected and then use this in your calculation.
This formula varible can be hidden from display in the query designer.
hope it gives you an idea.
regards,
CH
Similar Messages
-
Calculate no of execution month in query design
Hi,
I received requirements to create sales report as users would like to execute the sales report by entering the range of calendar month (eg: from 10.2010 to 12.2010). They would like to have average sales figures to be calculated as total sales / no of month (which is 3) that based on no of month that user had entered.
Can experts please share with me how can I achieve to calculate the no of month in query designer?
Thanks and regards,
Kang RingHi,
Please follow the below steps it will give you desired result.
Make a new formula in that put value 1 and exception aggregation as counter of all detailed values and refernce characterstic as calmonth so it will give you 1 against all the months you entered in the selection screen.Suppose you enter for a range of 3 months so you will get count 111 and in result you will get 3.
Now you want your sales to be divided by the sum of months count.
In order to achieve that create another fornula and put
SUMGT(formula1) formula 1 is the first formula you created.
After doing this you will get 3 against all your month.
Now create another formula and in that put your sales keyfigure and divide by formula 2.
After performing all the above steps you will get your desired result.
Hide formula 1 and formula 2.
Hope it works and fullfil your requirement.
Regards,
AL -
Using Calendar Year Month in query designer to populate a Month Structure
Hi
Is it possible to create a query that has a standard structure of Month Columns (Jan-Dec) with each month column populated by the correct 0CALMONTH (similar infoobject) value? I would also like to be able to filter this by the correct year selected since this will be a filter value.
Thanks for any help on this.Hi,
I would also like to be able to filter this by the correct year selected since this will be a filter value.
Yes. With the structure it is possible. But user input 0fiscalyear variable should be there to get the correct year data.
Hope it helps -
Count days in a month for a date range
i am trying to find no. of days between 2 Date Ranges for a list of Ids. i used the logic in the below link:
count days of the month
My query is giving duplicates since, I have list of Ids.
Doctor_ID Patient_ID ARRIVE_DT_TM DISCH_DT_TM
755722 42972229 10/18/2012 7:50 3/14/2013 20:45
763305 42972232 1/7/2013 20:27 3/15/2013 19:15
25391509 42972298 2/4/2013 22:45 3/8/2013 22:03
746779 42972331 1/4/2013 23:00 3/26/2013 21:50
763305 42972338 3/4/2013 22:19 3/6/2013 19:35
763305 42972411 11/4/2013 22:32 3/29/2013 17:30
I am looking for query to give me for Patient_ID = 42972229
MONTH COUNT_DAYS
201210 14
201211 30
201212 31
201301 31
201302 28
201303 14
I am running the following code and it loops through the months and gives duplicates when I remove where Patient_id IN (42972229)
select
Doctor_ID
, Patient_ID
, AR_DTTM
, DSC_DTTM
, TO_CHAR(ADD_MONTHS(TRUNC(date1, 'MONTH'), LEVEL - 1), 'YYYY MM') MONTHS_BET
, (LEAST(date2, ADD_MONTHS(TRUNC(date1, 'MONTH') - 1, LEVEL)) - GREATEST(date1, ADD_MONTHS(TRUNC(date1, 'MONTH'), LEVEL - 1)))+ 1 AS DAYSCOUNT
from (select
Doctor_ID
, Patient_ID
, ARRIVE_DT_TM AR_DTTM
, DISCH_DT_TM DSC_DTTM
,TRUNC(ARRIVE_DT_TM,'DDD') AS date1
,TRUNC(DISCH_DT_TM,'DDD') AS date2
from temp where Patient_id IN (42972229)
CONNECT BY LEVEL <= MONTHS_BETWEEN(TRUNC(date2, 'MONTH'), TRUNC(date1, 'MONTH')) + 1
Please help!Hi,
ASTRA_007 wrote:
Results I would like to see are:
Doctor_ID Patient_ID ARRIVE_DT_TM DISCH_DT_TM Month CountofDays
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2012 10 14
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2012 11 30
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2012 12 31
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2013 01 31
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2013 02 28
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2013 03 14
763305 42972232 1/7/2013 20:27 3/15/2013 19:15 2013 01 25
763305 42972232 1/7/2013 20:27 3/15/2013 19:15 2013 02 28
763305 42972232 1/7/2013 20:27 3/15/2013 19:15 2013 03 15
and so on...So each row represents a patient-month, and you want to display several columns from the temp table on each output row. In that case, include all those columns in both the SELECT and GROUP BY clauses, like this:
WITH universe AS
SELECT *
FROM temp
-- WHERE patient_id IN (42972229)
, date_range AS
SELECT TRUNC (MIN (arrive_dt_tm)) AS first_date
, TRUNC (MAX (disch_dt_tm)) AS last_date
FROM universe
, all_dates AS
SELECT first_date + LEVEL - 1 AS a_date
FROM date_range
CONNECT BY LEVEL <= (last_date + 1) - first_date
SELECT u.doctor_id
, u.patient_id
, u.arrive_dt_tm
, u.disch_dt_tm
, TO_CHAR ( TRUNC (a.a_date, 'MONTH')
, 'YYYY MM'
) AS month
, COUNT (*) AS count_days
FROM all_dates a
JOIN universe u ON a.a_date BETWEEN TRUNC (u.arrive_dt_tm)
AND u.disch_dt_tm
GROUP BY u.doctor_id
, u.patient_id
, u.arrive_dt_tm
, u.disch_dt_tm
, TRUNC (a.a_date, 'MONTH')
ORDER BY u.patient_id
, TRUNC (a.a_date, 'MONTH')
;Output from your sample data (with no filtering):
`DOCTOR_ID PATIENT_ID ARRIVE_DT_TM DISCH_DT_TM MONTH COUNT_DAYS
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2012 10 14
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2012 11 30
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2012 12 31
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2013 01 31
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2013 02 28
755722 42972229 10/18/2012 7:50 3/14/2013 20:45 2013 03 14
763305 42972232 1/7/2013 20:27 3/15/2013 19:15 2013 01 25
763305 42972232 1/7/2013 20:27 3/15/2013 19:15 2013 02 28
763305 42972232 1/7/2013 20:27 3/15/2013 19:15 2013 03 15
25391509 42972298 2/4/2013 22:45 3/8/2013 22:3 2013 02 25
25391509 42972298 2/4/2013 22:45 3/8/2013 22:3 2013 03 8
746779 42972331 1/4/2013 23:0 3/26/2013 21:50 2013 01 28
746779 42972331 1/4/2013 23:0 3/26/2013 21:50 2013 02 28
746779 42972331 1/4/2013 23:0 3/26/2013 21:50 2013 03 26
763305 42972338 3/4/2013 22:19 3/6/2013 19:35 2013 03 3
In the end the objective is to count the no. of days in each month between the arrival and discharge dates by Physician and for his/her patients.Then is the output above really what you want? Say you're interested in physician 763305. That physician had 18-patient days in March, 2013, but the output doesn't make it clear.
I ran your query, it works great but I have a long list of patients for whom I have to run these counts.the query above includes all patient_ids.
That's a separate problem, to be solved in the first sub-query, universe. The rest of the query will be unchanged.
How will you know which patients to include? If you can derive the list from temp itself, just use a WHERE clause in universe. If you need to look at other tables, join them in universe, or use them in sub-queries in universe, or both.
For exmple, if you decide that the list of patient_ids has no pattern, and that you'll need to store their ids in a separate table (perhaps a global temporary table), then universe might be:
WITH universe AS
SELECT t.* -- or list columns needed
FROM temp t
JOIN patient_ids_to_include p
ON p.patient_id = t.patient_id
) ...The rest of the query can be the same as above.
If a same patient is admitted again then Patient_ID will be different no matter when readmitted.Are you saying that patient_id identifies a visit, not a patient, and that the same person is assigned a different patient_id every time that person is admitted?
For
INSERT INTO temp (doctor_id, patient_id, arrive_dt_tm, disch_dt_tm)
VALUES ( 755722
, 42972229
, TO_DATE ('03/14/2013 23:00', 'MM/DD/YYYY HH24:MI')
, TO_DATE ('04/01/2013 12:00', 'MM/DD/YYYY HH24:MI')
First the Patient ID will be different from the earlier admission. Second the results will show like:
Doctor_ID Patient_ID ARRIVE_DT_TM DISCH_DT_TM Month CountofDays
755722 42972229 3/14/2013 23:00 4/1/2013 12:00 2012 03 14
755722 42972229 3/14/2013 23:00 4/1/2013 12:00 2012 04 1Are you saying that temp.patient_id is unique, and so the situation is impossible?
Edited by: Frank Kulash on May 7, 2013 10:23 AM -
What do you do in a query in order to find the 1st day of last month ?
i use a
select trunc(trunc(sysdate,'mon')-1,'mon') from dual;
what about you guys ?Hi,
Of all the solutions, I like yours
add_months(trunc(sysdate,'mm'),-1)or doing the operations in the opposite order, like Sentinel did
trunc(add_months(sysdate,-1),'mm')best, mainly because:
(1) it's easy to read and understand
(2) it's easy to modify (in case you want the first day from three months ago, or six months in the future)
By the way, after you post something on this forum, if you see that you've made a mistake, you can correct it. Click on the second icon to the left of "Reply". (What is that: a hand holding a pencil?) You don't need to post a second message. -
Extract the Month from the day with Query designer ...
Hi everybody,
Is there exist a method in Query designer to extract the CalMonth (Date Month) from the CalDay ?
Thanks!
Rodolphe.take reference from this step by step doc:
https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/25d98cf6-0d01-0010-0e9b-edcd4597335a -
Query to find the fifteenth day of a month
i want to know the fifteenth day of a month in oracle
can anyone send the queryHi,
Try this:
"afiedt.buf" 2 lines, 57 characters
1* SELECT TO_CHAR(TO_DATE('15-AUG-2006'),'Day') FROM DUAL
SQL>/
TO_CHAR(T
Tuesday
1 row selected.
SQL>Regards
Avinash -
Report for current day and current month
Hi gurus,
i 've a report, where i 've to display the values for qty and cost of the material for the current day and current month
HOw can i do this in BEx Query designer..If any document plz share
thanks
rakeshhi Kolli
here i want to filter the data on system date,
i wnt the report to pick the date dynamically based on the system date.
but i think restricting on calmonth and calday is not going to solve my scenario..
rakesh -
Successive dates with last day of that month being added to succesive date
Hi ,
I have a piece of code that displays the succuessive dates from the given date to tilll date with a date interval of 30 days. My requirement goes some thing like this. since the given date is '26-nov-08' the next successive date should be the number of days in nov(30) added to '26-nov-08'. that will be around 26-dec-08. For this date it has to add the number of days in December(31) to '26-dec-08' and that turns out to be '26-jan-09'. and this must go on till date.
In the below code i have used 30 for the interval of 30 days but the interval has to the last day of the successive date's month( for dec the interval has to 31 and for january the interval has to be 31 and for february 28)
select to_date('26-nov-08', 'dd-mon-yy') + (level - 1) * 30
from dual
connect by level <= trunc((sysdate-to_date('26-nov-08', 'dd-mon-yy'))/30 )Please advicehi ,
the query sent by you is correct and could it be in corporated for this query :
SELECT TRUNC(inst_due_date) + (LEVEL-1 ) * (ilpa_term_type),iloan_code,LOAN_AMT,FEE_AMT,
LOAN_DATE,LOAN_STATUS_ID
FROM (
SELECT inst_due_date,sm.iloan_code,LOAN_AMT,
FEE_AMT,
LOAN_DATE,
LOAN_STATUS_ID,
decode(sm.ilp_term_type, 26 ,14,24,15,12,(select to_number(to_char(last_day(inst_due_date),'dd')) from dual)) as ilpa_term_type
FROM ST_IL_SCHEDULE sc,ST_IL_MASTER sm
WHERE sc.iloan_code = sm.iloan_code
AND sc.inst_num = (SELECT MAX(inst_num) FROM ST_IL_SCHEDULE b WHERE b.iloan_code = sc.iloan_code)
AND sc.iloan_code =123456789)
CONNECT BY LEVEL <= TRUNC((TRUNC(SYSDATE)-TRUNC(inst_due_date))/(ilpa_term_type) )
Here we are using the decode concept if ilp_term_type = 26 then 14 but we need to implement the code of adding the number of days to that month in place of this code :
select to_number(to_char(last_day(inst_due_date),'dd')) from dual:
Please advice -
Last day of each month in a year based on a Input date?
Hi all,
I have a request from a customer who wants to have a yearly report created in BEx Query Designer which starts in January up to December and they want to have a Month To Date (MDT) and Year to Date (YTD) calculation of a key figure. This report will only show one year at the time based on the date the user give as input at the Variable Screen.
This key figure should be calculated by using the last date of each month for input when performing the MTD and YTD calculation and summarizations.
Example:
January: 31.01.2008 Key Figure = 1000. MTD = 1000 and YTD = 1000
February: 29.02.2008 Key Figure = 2500. MTD = (2500-1000) 1500 and YTD = 2500
March: 31.03.2008 Key Figure = 6000. MTD =(6000-2500)=3500 and YTD = 6000
Etcu2026.
This means that I have to have a lot of hidden Key figures which gets restricted on the different month end dates and formulas to calculate the different MTD and YTD results for the months as the year progresses.
The way I have solved it now is that I have a Customer Exit which gives me the Last day of last year (Exp: 31.12.2007) based on input date and use a Offset on the last day of last year date to get the different last dates of each month.
Since we have a leap year (one extra day in February) this year, the offset to calculate the end month dates will be different for 2007 and next year (2009). This solution is not very flexible, and it will not give the correct MTD and YTD if the customer wants to go back to 2007 and off course next year (2009).
One solution is to create 12 Customer Exits that gives me the different month end dates (January-December), and also takes in account leap year for February for the different years. These Exits will be based on the Input date the Customers put in at the variable screen.
I would rather want to avoid making 12 new customer exits and want your advice and expertise to find out if this is possible in any other way (maybe with only 1 customer exit) to get the last date of each month based on an input date.
Thanks for all your advices on beforehand.
Regards
Oddmar LidHi,
Thanks for you replay and documentation, but it doesn't give me excatly the functionality I'm after. The only MTD calculation code the document provides is the calculation of the following functionality:
"Month to Date (MTD) u2013 From the 1st of month to u201CKey Dateu201D - for current year." This doesn't give the the functionality I want, which is to retrieve a given vaule for a Key Figure for the last dates of the months in a year to calculate MTD and YTD.
This way I have created the query is to have multiple hidden Key Figures that calculates the MTD and YTD.
In Columns in Query Designer it will look something like this:
Selection: MTD January--> Date = 31.01.2008, Key Figure (Always Show)
Selection: YTD January --> Date= 31.01.2008, Key Figure (Always Show)
Selection: MTD February --> Date= 29.02.2008, Key Figure (Always Hide)
Formula: MTD February --> MTD February - MTD January (Always Show)
Selection YTD February --> Date = 29.02.2008, Key Figure (Always Show)
And so on....
This is off course a simplified version, but it shows the core of the solution. What I want to achive here is that the dates used to get the Key Figures (last date of a month) is calculated as flexible as possible, so that the users can go back and forth in time without worrying about the leap year problem and so on. I have now used an offset from the last date of last year and this is good for all the normal years, but when it is a leap year the query will use wrong dates to get the key figure vaule for the last date of each month.
Any ideas on how to achieve this without creating 12 different Customer Exit variables (one for each end date of each month)?
Thanks
Regards
Oddmar Lid -
How to get same day of a month in every year in the DB ( To update a flag )
Hi,
I am trying to formulate an update query for a flag table in our database which contains dates, and flag columns. Currently the system have dates for the next ten years. The flags are updated with values 0 or 1 if a particular date falls under the required criteria.
I need to update flag column for the same day of the month in every year. e.g. 2nd Sunday of October. The value should be updated to all years in the table. Currently I am using the following query to update the current year.
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7;
and for next year Like
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = add_months(NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7,+12)-1;
This is not an excellent way to do it as it does not take care of leap years and it does not scan and update values in the whole table for all years correctly.
Can any one help me to resolve this please.Hi,
user10903866 wrote:
Hi,
I am trying to formulate an update query for a flag table in our database which contains dates, and flag columns. Currently the system have dates for the next ten years. The flags are updated with values 0 or 1 if a particular date falls under the required criteria.
I need to update flag column for the same day of the month in every year. e.g. 2nd Sunday of October. The value should be updated to all years in the table. Currently I am using the following query to update the current year.
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7;That's the 2nd Sunday after October 1; the 2nd Sunday of October is the 2nd Sunday after September 30, so you need to subtract 1 more day before calling NEXT_DAY.
I'd do it this way:
WHERE c_date = NEXT_DAY ( TO_DATE ( '01-OCT-2013', 'DD-MON-YYYY') - 8
, 'SUNDAY'
) + (7 * 2) -- Last number is week numberRemember, calling NEXT_DAY like this depends on your NLS_DATE_LANGUAGE.
and for next year Like
UPDATE FILTERCALENDAR SET YEAR_WINDOW=1 WHERE c_date = add_months(NEXT_DAY( TO_DATE('OCT-2013','MON-YYYY'), 'SUNDAY') + (2-1)*7,+12)-1;If you want the 2nd Sunday in October, 2014, then take the previous expression, and just change 2013 to 2014:
WHERE c_date = NEXT_DAY ( TO_DATE ( '01-OCT-2014' -- or any month and year you want
, 'DD-MON-YYYY'
) - 8
, 'SUNDAY'
) + (7 * 2) -- Last number is week number
This is not an excellent way to do it as it does not take care of leap years and it does not scan and update values in the whole table for all years correctly.
Can any one help me to resolve this please.
I hope this answers your question.
If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
In the case of a DML operation (such as UPDATE) the sample data should show what the tables are like before the DML, and the results will be the contents of the changed table(s) after the DML.
Explain, using specific examples, how you get those results from that data.
See the forum FAQ {message:id=9360002} -
If Current Month then use last day, else use month
My cube is setup where the current month is at a daily level and the previous months just contain the last day of data.
I would like to for the last month to only return the last day and return the month level for all previous months. The reason being is our third party software gives us the capability of doing a drillthrough, but when doing it for the latest month, it is
returning every day in that month.
Here is my attempt, but it is only returning the last month, not the rest of the months.
select [Measures].[Current Balance]
on 0, non empty
[Date].[Month].children
on 1
from [MyCube]
where
IIF([Date].[Month].CurrentMember = ClosingPeriod([Date].[Month].[Month]),
TAIL (NonEmpty([Date].[Date].members,[Measures].[Count Of Accounts]),1),
[Date].[Month].CurrentMember)Hi Dodge,
I’m writing to follow up with you on this post. Was the problem resolved by the above query?
If the issue was solved, I’d like to mark this issue as "Answered". Please also feel free to unmark the issue, with any new findings or concerns you may have.
Thanks,
Charlie Liao
TechNet Community Support -
Elapse days - calculation from month and year
Duplicate thread ...
coding required for converting month into days
I have Month and year field in my DSO --Year( 2009), Month(4)
I want below logic to calculate -
MTD qty % = (qty * elapse days) / no of days in month
so from the above, I want to know,
1. How can we get the no of days from the above 2 objects (year and month).
2. Elapse days are the days that are over from current date to Ist day of that month.
eg: current date - 04.03.2009 , 1st day of the month - 04.01.2009,
elapse days = 2. (you need to consider all days in the month, not only working days)
so my questions is how can we get, # of days n a month from above 2 fields and elapse days based on the above condition.
also want to know, where can I have the logic in transformations or query level.
please provide your suggestions.
Thanks,
Pra
Edited by: Arun Varadarajan on Apr 5, 2009 10:44 PM
Edited by: Arun Varadarajan on Apr 5, 2009 10:45 PMHello,
I think the sample program below does what you ask: it finds the days in the month (bit of an overkill to use function modules for that) and then computes the QTD.
Note that the internal string representation of a data variable is always YYYYMMDD, regardless of the "externalized" form (e.g. yyyy/mm/dd or dd.mm.yyyy), so this code will work regardless of your custom date format.
Regards,
Mark
REPORT zqty_to_date.
PARAMETERS:
p_date TYPE dats,
p_qty TYPE i.
DATA:
days TYPE i,
n_year TYPE numc4,
n_month TYPE numc2,
n_day TYPE numc2,
qtd(6) TYPE p DECIMALS 1.
START-OF-SELECTION.
n_year = p_date+0(4).
n_month = p_date+4(2).
n_day = p_date+6(2).
PERFORM days_in_month USING n_year n_month CHANGING days.
qtd = ( p_qty * ( n_day - 1 ) ) / days.
WRITE: / 'Days in month:', days,
/ 'Qty to date :', qtd.
*& Form days_in_month
* text
FORM days_in_month USING year month CHANGING days.
DATA: ymod4 TYPE i,
ymod100 TYPE i,
ymod400 TYPE i.
CASE month.
WHEN 4 OR 6 OR 9 OR 11.
days = 30.
WHEN 2.
ymod4 = year MOD 4.
ymod100 = year MOD 100.
ymod400 = year MOD 400.
IF ( ymod4 = 0 AND ymod100 > 0 ) OR ( ymod100 = 0 AND ymod400 = 0 ).
days = 29.
ELSE.
days = 28.
ENDIF.
WHEN OTHERS.
days = 31.
ENDCASE.
ENDFORM. "days_in_month -
Show data of last day of previous month against any day of current month
Hi,
I have fact table which contains data at date level (we have data for oct-2009 to april-2010). Our requirement is to show data of last day of previous month against any day of current month in obiee 11g. I am facing problem in Feb 2010 its picking data of 28-Jan-2010 instead of 31-jan-2010 and for April its picking data of 30-mar-2010 instead of 31-mar -2010.
Any suggestion ???You're asking to filter your data set to only include rows between:
1) last day of the previous month
2) any day of the current month
This can be achieved with prompting in OBIEE Answers.
last day of previous month = TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE)) . The problem is you need to make query work within Oracle's Answer syntax.
In the prompt, select the operator type for your date dimension as 'between' and default to 'SQL Results'.
For the 'last day of previous month' , use the query:
SELECT
case when 1=0 then Time."Fiscal Date" else TIMESTAMPADD( SQL_TSI_DAY , -(1), TIMESTAMPADD( SQL_TSI_DAY , DAYOFMONTH( CURRENT_DATE) * -(1) + 1, CURRENT_DATE))
end
FROM ENTER_YOUR_PRESENTATION_FACT_FOLDER_HERE
For the current date, use the query:
SELECT
case when 1=0 then Time."Fiscal Date" else CURRENT_DATE
end
FROM ENTER_YOUR_PRESENTATION_FACT_FOLDER_HERE
Another option is to create a last_date_pervious_month variable in the RPD and have that as the default value in your prompt. -
Hi guys
I am newbie in vb net and I want your help to solve a problem.
I have this datagridview with two columns and all days of a month in custom columns.
[IMG]http://i59.tinypic.com/2qwpj15.png[/IMG]
I also have one combobox to change Year and a combobox to change Month.
Here is the code to load data
Private Sub fill_plan()
dgMonth.Rows.Clear()
Try
Dim i As Integer = 0
Dim query As String = "SELECT MonID,Unitname,Personel,Udate FROM tblMonth ORDER BY Unitname"
con.Open()
cmd = New OleDbCommand(query, con)
myDR = cmd.ExecuteReader
If myDR.HasRows Then
While myDR.Read
dgMonth.Rows.Add()
dgMonth.Rows(i).Cells(0).Value = myDR.GetInt32(myDR.GetOrdinal("MonID"))
dgMonth.Rows(i).Cells(1).Value = myDR.GetString(myDR.GetOrdinal("Unitname"))
dgMonth.Rows(i).Cells(2).Value = myDR.GetInt32(myDR.GetOrdinal("Personel"))
i = i + 1
End While
End If
myDR.Close() : con.Close()
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
End Sub
With
this code the
personel column
loads the first
day of the month.
I want to load
the column the date that is
in the database.Hello,
This can be done with less code
Private Sub fill_plan()
dgMonth.DataSource = Nothing
Dim dt As New DataTable
Try
Dim query As String = "SELECT MonID,Unitname,Personel,Udate FROM tblMonth ORDER BY Unitname"
con.Open()
cmd = New OleDbCommand(query, con)
dt.Load(cmd.ExecuteReader)
dgMonth.DataSource = dt
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Error")
End Try
End Sub
The above loads all rows, if you want to limit the rows placed in the DataGridView this is best done in the SQL via WHERE conditions and/or with SELECT TOP x.
Formatting of the data is best done via the property window for the DataGridView on whatever column you want too. Using the above you now need to set the data property for each column and set dgMonth.AutoGenerateColumns = False, in the end we end up with
less code
edit is there a reason for returning the primary key? If so then using my method we can hide that field but I see no reason for having it in this case
Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem.
Maybe you are looking for
-
Erasing songs that no longer exist question
So if you have deleted the file or also in my case renamed the song and moved it to another location, when you click on the song it says no longer exists and displays a ? beside its name now. My question is there a way to erase all songs that no long
-
Hi, I will be creating animations in After Effects mostly using Illustrator vector files and will be exporting to SWF or XFL for using the animations on the web. One of the priorities is light data as possible to provide viewers with slower connectio
-
NT domain authentication impelmented in weblogic server
hello Sir, I would like to find out if there is any package with weblogic server that will allow me to authenticate the users of weblogic using an NT domain authentication. Any user of weblogic should be an authenticated user of an NT domain and i am
-
Missing Screen Savers and other crazy happenings...
I recently noticed that the screen saver list in my Screen Saver pref window is blank. As a result, one I open this window, I generally lose control over my keyboard/mouse. I am unable to quit, close the pref window, tab to other apps, etc. I've t
-
Dump In Dynamic Internal Table
REPORT ZDYNAMIC_INTERNAL_TABLE. TYPE-POOLS : abap. FIELD-SYMBOLS: <fs_table> TYPE STANDARD TABLE, <fs_wa>, <fs_field>. DATA: it_table TYPE REF TO data, it_line TYPE REF TO data, xfc TYPE LVC_S_FCAT, i