Qry based on Weekdays
Hello experts,
I work in T-SQL and Microsoft tools but currently am building a report that runs of an Oracle dB..hence having certain problems converting T-SQL format into Oracle.
Pls help me out.
I have a reporting requirement that needs to run between Monday to Friday.
IF sysdate is between monday to thursday THEN
Volume of PreWork = count of orders
where
[Created_Date] < sysdate AND [Ship_Date] = nextday
IF sysdate is Friday THEN
Volume of PreWork = count of orders
where
[Created_Date] < sysdate AND ([Ship_Date] > sysdate and [Ship_Date] <= monday) (i.e. sat, sun & mon)
Am a bit confused with the CASE statements...Pls help !
Hi Centinul,
Your qry definitely meets my requirement but I would be running this report using Microsoft reporting services hence is there any way I can amend it to run as a Query and not a procedure or package.
Also when I run the qry you supplied, I am getting counts against both IF and ELSE IF statement...I assume basically I should get a count against IF statement as its weekday '1' today....pls correct my understanding.
New query is (I have also changed the date format because earlier it did not return any result)
IF TO_NUMBER(TO_CHAR(SYSDATE,'D')) BETWEEN 1 AND 4 THEN
SELECT
count(SALES_ORDER_HEADER.SOH_ORDER_NO) as COUNT_ORDERS
FROM
COM.SALES_ORDER_HEADER SALES_ORDER_HEADER
WHERE
SALES_ORDER_HEADER.SOH_CLASS = 'CB'
AND to_char(SOH_DATE_CREATED,'dd/mm/yyyy') < to_char(sysdate,'dd/mm/yyyy')
AND to_char(SOH_DATE_SHIP,'dd/mm/yyyy') = to_char(sysdate+1,'dd/mm/yyyy');
ELSE IF TO_NUMBER(TO_CHAR(SYSDATE,'D')) = 5 THEN
SELECT
count(SALES_ORDER_HEADER.SOH_ORDER_NO) as COUNT_ORDERS
FROM
COM.SALES_ORDER_HEADER SALES_ORDER_HEADER
WHERE
SALES_ORDER_HEADER.SOH_CLASS = 'CB'
AND to_char(SOH_DATE_CREATED,'dd/mm/yyyy') < to_char(sysdate,'dd/mm/yyyy')
AND SOH_DATE_SHIP BETWEEN TRUNC(SYSDATE) AND TRUNC(NEXT_DAY(SYSDATE,'MONDAY'));
Similar Messages
-
Hi all,
Please let me know, if payment term like - The 2nd Friday of 1st. Month is possible in SAP?
If yes, let me know the steps please.
Regards,
SrideviHi,
Pls. let me know if it is possible or not?
Regards,
Sridevi -
Identify What are the days present in weekdays value of recurrenceinfo field
Hi,
I want the particular days based on weekdays values in recurrenceinfo field for appointment.The values of days as sunday 1,monday 2,tuesday 4,wednesday 8,thursday 16,friday 32 and saturday 64.Now the weekdays = 65 which means in this
saturday 64 and sunday 1 is contained.So i want the query for identifying days in weekdays values.Just do a boolean and operator with 65 (64 | 1 ie both saturday and sunday) to check the presence
For example say recurrenceinfo field is set for Mon,Wed and Fri
then value would be 2 | 8 | 32 = 42
Now & with 65 and you will get 0 as there are no overlaps
SELECT 2 | 8 | 32
SELECT 42 & 65
So your filter should be like this
WHERE recurrenceinfo & 65 = 0
for no overlap
Please Mark This As Answer if it solved your issue
Please Vote This As Helpful if it helps to solve your issue
Visakh
My Wiki User Page
My MSDN Page
My Personal Blog
My Facebook Page -
Error in using one's collection values in other collection
hi,
I want to fetch cursor s values based upon cursor r part_no column to populate childbkp table.but i m getting eror .plz help me to resolve.in code it might b many mistakes also.
declare
TYPE PartNum IS TABLE OF parent.part_num%TYPE
INDEX BY BINARY_INTEGER;
pnum_t PartNum;
TYPE PartName IS TABLE OF parent.part_name%TYPE
INDEX BY BINARY_INTEGER;
pnam_t PartName;
CURSOR r IS
SELECT part_num, part_name
FROM parent;
type r_part_num_arry IS TABLE OF r%rowtype;
r_part_num r_part_num_arry;
r_pnum_t parent.PART_NO%type;
CURSOR s IS
SELECT part_num, part_name
FROM parent p where rownum=1 and p.PART_NO = r_pnum_t ;
BEGIN
OPEN r;
LOOP
FETCH r BULK COLLECT INTO pnum_t, pnam_t LIMIT 1000;
FORALL i IN pnum_t.FIRST .. pnum_t.LAST
INSERT INTO child
(part_num, part_name)
VALUES
(pnum_t(i), pnam_t(i));
COMMIT;
begin
OPEN s;
LOOP
r_pnum_t := pnum_t(i);
FETCH s BULK COLLECT INTO pnum_t, pnam_t LIMIT 1000;
FORALL i IN pnum_t.FIRST .. pnum_t.LAST
INSERT INTO child_bkp
(part_num, part_name)
VALUES
(pnum_t(i), pnam_t(i));
COMMIT;
EXIT WHEN s%NOTFOUND;
END LOOP;
COMMIT;
CLOSE s;
end;
EXIT WHEN r%NOTFOUND;
END LOOP;
COMMIT;
CLOSE r;
END ;i need to run 1st qry based upoin below senerio.i need to do this work in collection case also.how to do it by collection.
declare
CURSOR r IS
SELECT part_num, part_name
FROM parent;
r_pnum_t parent.PART_Num%type;
pnum_t parent.PART_Num%type;
pnam_t parent.PART_Name%type;
CURSOR s IS
SELECT part_num, part_name
FROM parent p where rownum=1 and p.PART_Num = r_pnum_t ;
BEGIN
OPEN r;
LOOP
FETCH r INTO pnum_t, pnam_t ;
INSERT INTO child(part_num, part_name)
VALUES(pnum_t, pnam_t);
begin
OPEN s;
LOOP
r_pnum_t := pnum_t ;
FETCH s INTO pnum_t, pnam_t ;
INSERT INTO child_bkp(part_num, part_name)
VALUES(pnum_t, pnam_t);
COMMIT;
EXIT WHEN s%NOTFOUND;
END LOOP;
COMMIT;
CLOSE s;
end;
EXIT WHEN r%NOTFOUND;
END LOOP;
COMMIT;
CLOSE r;
END -
Best pratices for RMAN backup management for many databases
Dear all,
We have many 10g databases (>40) hosted on multiple Windows servers which are backup up using RMAN.
A year ago, all backup's were implemented through Windows Scheduled Tasks using some batch files.
We have been busy (re)implementing / migrating such backup in Grid Control.
I personally prefer to maintain the backup management in Grid Control, but a colleague wants now to go back to the batch files.
What i am looking for here, are advices in the management of RMAN backup for multiple databases: do you guys use Grid Control or any third-party backup management tool or even got your home-made solution?
One of the discussion topic is the work involved in case that the central backup location changes.
Well... any real-life advices on best practices / strategies for RMAN backup management for many databases will be appreciated!
Thanks,
ThierryHi Thierry,
Thierry H. wrote:
Thanks for your reaction.
So, i understand that Grid Control is for you not used to manage the backups, and as a consequence, you also have no 'direct' overview of the job schedules.
One of my concern is also to avoid that too many backups are started at the same time to avoid network / storage overload. Such overview is availble in Grid Control's Jobs screen.
And, based on your strategy, do you recreate a 'one-time' Oracle scheduled job for every backup, or do your scripts create an Oracle job with multiple schedule?
You're very welcome!
Well, Grid Control is not an option for us, since each customer is in a separate infrastructure, and with their own licensing. I have no real way (in difference to your situation) to have a centralized point of control, but that on the other hand mean that I don't have to consider network/storage congestion, like you have to.
The script is run from a "permanent" job within the dba-scheduler, created like this:
dbms_scheduler.create_job(
job_name => 'BACKUP',
job_type => 'EXECUTABLE',
job_action => '/home/oracle/scripts/rman_backup.sh',
start_date => trunc(sysdate)+1+7/48,
repeat_interval => 'trunc(sysdate)+1+7/48',
enabled => true,
auto_drop => false,
comments => 'execute backup script at 03:30');and then the "master-script", determines which level to use, based on weekday from the OS. The actual job schedule (start date, run interval etc) is set together with the customer IT/IS dept, to avoid congestion on the backup resources.
I have no overview of the backup status, run times etc, but have made monitoring scripts that will alert me if/when a backup either fails, or runs for too long. This, in addition with scheduled disaster/recovery tests makes me sleep rather well at night.. ;-)
I realize that there (might be) better ways of doing backup scheduling in your environment, since my requirements are so completely different than yours, but I guess that we all face the same challenges in unifying the environments as much as possible, to minimize the amount of actual work we have to do. :-)
Good luck!
//Johan -
Weekdays option in alarm does not correspond to first day of the week option in calendar
I am based in Oman where the week is Saturday to Thursday and Friday is weekly off instead of Sunday. Inspite of changing first day of the week to saturday in calendar option and choosing weekdays option in Alarm, it rings on Fridays and does not ring on Sundays. Its very upsetting. Can anyone suggest a solution for this?? Thanks in advance.
i just did this on my Blackberry curve 8330 to make sure my answer was correct, and what i was able to do was.
Go to your calender, select the first day you would like it to start i i will start monday for example, Recurrence set to weekly. when selecting weekly another option will appear below it ( S M T W T F S ) highlight and select a letter that marks the day Saturday , Monday , Tuesday Ect. and the letting will become BOLD meaning it is selected. Thus giving you the option to select any , and as many days per week you wish, and have the recurrence as often as you want -
Need to fetch value from a table based on data range
Hello there,
I was hoping that the community could give me a hand with this little puzzle I got.
I am currently creating a Time Dimension for a data wharehouse, and I have the requirement to populate a column named SEASON (e.g: Summer, Winter, Spring, Autumn) for each date row. So for the 20/Dec/2013, the Season column must say Winter.
Here is now my Time Dimension table looks like, without the Season information (which I yet have to load):
DimTime Table
TIMEID
FULLDATE
YEAR
SEASON
MONTH
MONTHDAY
WEEK
WEEKDAY
274
02-MAR-10
2010
3
2
9
2
275
03-MAR-10
2010
3
3
9
3
276
04-MAR-10
2010
3
4
9
4
277
05-MAR-10
2010
3
5
9
5
278
06-MAR-10
2010
3
6
9
6
279
07-MAR-10
2010
3
7
9
7
This entire table is being populated using Oracle functions to manipulate a date field from another table, named PDATE:
My ETL Code
INSERT INTO DimTime(timeid, fulldate, year, month, monthday, week, weekday)
SELECT tim_seq.NEXTVAL, pdate, year, month, monthday, week, weekday
FROM (SELECT DISTINCT pdate, EXTRACT(year from pdate) year, EXTRACT(month from pdate) month,
EXTRACT(day FROM pdate) monthday, to_number(to_char(to_date(pdate,'DD/MM/YY'),'IW')) week,
TO_CHAR(pdate, 'D') weekday
FROM Performance PER
ORDER BY pdate);
NOTE: Code considers the table DimTime to be truncated every time it loads (i.e.: I don't need to consider additional loads).
As you can see, Season wasn't populated. Since the solstices and equinoxes vary for each year, I can't just say that Summer start at a given date (e.g: 21 of June) because one year it could be the 19/Jun, another the 22/Jun, etc. So in order to solve this problem, I have a table named Season which defines the START and END dates for the seasons:
Season Table
SEASON#
SEASONNAME
YEAR
DATEFROM
DATETO
1
Spring
2010
01-MAR-10
30-MAY-10
2
Summer
2010
31-MAY-10
29-AUG-10
3
Autumn
2010
30-AUG-10
28-NOV-10
4
Winter
2010
29-NOV-10
27-FEB-11
5
Spring
2011
28-FEB-11
29-MAY-11
6
Summer
2011
30-MAY-11
28-AUG-11
7
Autumn
2011
29-AUG-11
27-NOV-11
8
Winter
2011
28-NOV-11
26-FEB-12
9
Winter
2009
30-NOV-09
28-FEB-10
This is the bit I don't know how to do. How can I make sure that I populate the correct Season in my DimTime table based on the season specified in the Season table?
Thanks in advance for your help!
Regards,
P.Just join to table Season:
INSERT
INTO DimTime(
timeid,
fulldate,
year,
month,
monthday,
week,
weekday,
seasonname
SELECT tim_seq.NEXTVAL,
pdate,
year,
month,
monthday,
week,
weekday
FROM (
SELECT DISTINCT pdate,
EXTRACT(year from pdate) year,
EXTRACT(month from pdate) month,
EXTRACT(day FROM pdate) monthday,
to_number(to_char(to_date(pdate,'DD/MM/YY'),'IW')) week,
TO_CHAR(pdate,'D') weekday,
seasonname
FROM Performance PER,
season
WHERE pdate between datefrom and dateto
SY. -
SQL Server Reporting Services- Coloring a Cell Background Based on two different column group values
Hello All,
I have a matrix report with time scale on the x axis and Resources on Y axis Showing the tasks assigned to each resource for a period of time. Here I have to color a matrix cell showing task details on tool tip with background color of the cell.
So Please help me on this.I have a expression like this...
In my case the color should be filled for the cell with name "Fields!task_name.Value" based on the values of "Fields!Day_Wise.Value " where we have the values for Daywise as S,M,T,W,T,F,S. So i need the background for the cell with name
task_name as Light Grey on Friday and Saturday, But we have the same name S for sunday also, which should come in different color.
=iif(Fields!Day_Wise.Value ="F","LightGrey",
IIF(PREVIOUS(Fields!Day_Wise.Value) ="F","LightGrey",
iif(Fields!task_name.Value="","White",
iif(InStr(Fields!task_name.Value,"||")>0,"Maroon",
iif(InStr(Fields!task_name.Value,"NULL")>0,"Sienna",
iif(InStr(Fields!task_name.Value,"Pink")>0,"Pink",
iif(InStr(Fields!task_name.Value,"Red")>0,"Red",
iif(InStr(Fields!task_name.Value,"Purple")>0,"Purple",
iif(InStr(Fields!task_name.Value,"Green")>0,"Green",
iif(InStr(Fields!task_name.Value,"White")>0,"White",
iif(InStr(Fields!task_name.Value,"Cyan (Teal)")>0,"Teal",
iif(InStr(Fields!task_name.Value,"Olive")>0,"Olive",
iif(InStr(Fields!task_name.Value,"Blue")>0,"Blue",
iif(InStr(Fields!task_name.Value,"Light Blue (Aqua)")>0,"LightBlue",
iif(InStr(Fields!task_name.Value,"Yellow")>0,"Yellow","Black"
Thanks
AJ HameedHi AJ Hameed,
According to your description, you want to set the background color for the cells based on the values inside of cells and the values the column group. You want to set grey for cells on Friday and Saturday, set colors based on the task name on other weekdays.
Right?
In Reporting Services, there's no problem if we have two different data values in conditional expression, so we can set background color based on Day_Wise or task_name. One issue in this scenario is, we can't have value "S" for both Saturday and Sunday when
working in a matrix. Otherwise the task_name will overwrite the previous task_name (for numeric values, it will do sum calculation). So we suggest you change the values for weekdays in database. The expression you have posted was correct. It only has a small
issue: the "Light Blue(Aqua)" also contains "Blue", so when doing conditional judging, the expression will return "Blue" instead of "Light Blue". We have tested in our local environment. For viewing convenience, we used the Switch() function in our expression:
=IIf(Fields!Day_Wise.Value="Fri" or Fields!Day_Wise.Value="Sat","LightGrey",
Switch(
InStr(Fields!Task_name.Value,"White")>0,"White",
InStr(Fields!Task_name.Value,"||")>0,"Maroon",
InStr(Fields!Task_name.Value,"Pink")>0,"Pink",
InStr(Fields!Task_name.Value,"Red")>0,"Red",
InStr(Fields!Task_name.Value,"Purple")>0,"Purple",
InStr(Fields!Task_name.Value,"Green")>0,"Green",
InStr(Fields!Task_name.Value,"Cyan(Teal)")>0,"Teal",
Fields!Task_name.Value="","White",
InStr(Fields!Task_name.Value,"Olive")>0,"Olive",
InStr(Fields!Task_name.Value,"Blue")>0,"Blue",
InStr(Fields!Task_name.Value,"Aqua")>0,"LightBlue",
InStr(Fields!Task_name.Value,"Yellow")>0,"Yellow",
InStr(Fields!Task_name.Value,"Orange")>0,"Orange",
InStr(Fields!Task_name.Value,"Null")>0,"Sienna",
true,"Black"
The result looks like below:
Reference:
Matrices (Report Builder and SSRS)
If you have any question, please feel free to ask.
Best Regards,
Simon Hou -
Compare two columns and formate based on condition
I know this dead horse has been beaten and I've read my fair share of threads and manuals to no avail.. I have two list that consist of movie titles, holiday movies to be exact. I'm creating a holiday movie schedule which consist of three(3) columns...A,B and C. Column A is the Date, Sat, November 17 2012 thru Monday, Dec 24, 2012. Column C consist of a movie list divided into 2 sections with three subsections each. Section 1 is animated movies and Section 2 is live action, each subsection, 1.1, 1.2, 1.3, 2.1, 2.2 and 2.3 are lists based on popularity with the kids...low, medium and high respectively. And finally column B is the movie list relative the column A...the schedule.
As I write a movie title in column B, I'd like the cell fill to be light red and the corresponding title in column C change to strike through font type. This way I know I've added the movie title to the schedule...this comes in handy when I ask the kids to help so we have no duplicates in the schedule. I'm assuming this would take a combination of; Conditional Formatting, cell formulas and perhaps an additional blank column for trigger results.
I'm including the table, which include an experimental column I was working on. As an FYI, this has been completed in Excel already, just hoping to get it done in Numbers.
Thanks for any help anyone can give.
Date
Movie Name
Class
Sat, Nov 17, 2012
Animated Christmas Movies
TRUE
Lowest Priority Animation
TRUE
Frosty Returns
TRUE
Sun, Nov 18, 2012
The Nightmare Before Christmas
Rudolph and Frosty's Christmas in July
TRUE
Rudolph the Red-Nosed Reindeer & the Island of Misfit Toys
TRUE
Rudolph's Shiny New Year
TRUE
Mon, Nov 19, 2012
Nothing Like the Holidays
TRUE
Medium Priority Animation
TRUE
Jack Frost Animation
TRUE
Tue, Nov 20, 2012
Home for the Holidays
It's Christmas Time Again, Charlie Brown
TRUE
Christmas in South Park
TRUE
Cartoon Network Christmas Rocks
TRUE
Wed, Nov 21, 2012
Planes, Trains and Automobiles
Cartoon Network Christmas Yuletide Follies
TRUE
Cartoon Network Christmas Vol3
TRUE
Twas the Night Before Christmas
TRUE
Thu, Nov 22, 2012
Planes, Trains and Automobiles
The Little Drummer Boy
TRUE
TRUE
Highest Priority Animation
TRUE
Fri, Nov 23, 2012
Trapped in Paradise
The Simpson's Christmas
TRUE
A Very Special Family Guy Freakin' Christmas
TRUE
Family Guy: Road To The North Pole
TRUE
Sat, Nov 24, 2012
American Dad! The Most Adequate Christmas Ever
TRUE
A Charlie Brown Christmas
TRUE
The Nightmare Before Christmas
FALSE
Sun, Nov 25, 2012
Die Hard
Frosty the Snowman
Die Hard 2
Hooves of Fire
How the Grinch Stole Christmas
Mon, Nov 26, 2012
Gremlins
Santa Claus is Comin' to Town
The Year Without a Santa Claus
Rudolph, the Red-Nosed Reindeer
Tue, Nov 27, 2012
The Ice Harvest
Live Action Christmas Movies
Lowest Priority
Wed, Nov 28, 2012
Reindeer Games
National Lampoon's Christmas Vacation 2: Cousin Eddie's Island Adventure
Chasing Christmas
The Nativity Story
Thu, Nov 29, 2012
Bad Santa
Unaccompanied Minors
Jingle All the Way
Jack Frost Live
Fri, Nov 30, 2012
The Shop Around the Corner
The Santa Clause 3: The Escape Clause
The Santa Clause 2: The Mrs. Clause
Sat, Dec 1, 2012
The Bishop's Wife
Medium Priority
0
Bad Santa
Bad Santa
Mixed Nuts
Mixed Nuts
Sun, Dec 2, 2012
The Chronicles of Narnia: The Lion, the Witch and the Wardrobe
Reindeer Games
Reindeer Games
The Ice Harvest
The Ice Harvest
The Shop Around the Corner
The Shop Around the Corner
Mon, Dec 3, 2012
Miracle on 34th Street B&W
The Bishop's Wife
The Bishop's Wife
Christmas in Connecticut
Christmas in Connecticut
The Chronicles of Narnia: The Lion, the Witch and the Wardrobe
The Chronicles of Narnia: The Lion, the Witch and the Wardrobe
Tue, Dec 4, 2012
Mixed Nuts
Nothing Like the Holidays
Nothing Like the Holidays
Home for the Holidays
Home for the Holidays
The Family Man
The Family Man
Wed, Dec 5, 2012
Scrooged
Miracle on 34th Street 1994
Miracle on 34th Street 1994
Miracle on 34th Street B&W
Miracle on 34th Street B&W
Just Friends
Just Friends
Thu, Dec 6, 2012
Just Friends
Trapped in Paradise
Trapped in Paradise
0
Highest Priority
0
Fri, Dec 7, 2012
Miracle on 34th Street 1994
Die Hard
Die Hard
Die Hard 2
Die Hard 2
Gremlins
Gremlins
Sat, Dec 8, 2012Hi Stephen,
Both of these are solvable, and the Date solution cold be similar to that used for the 'stock list' in column C. The Movie Title solution is a different case, though.
The stock list is edited only occasionally, so requiring the user to unhide column C, add a title, then rehide the column is workable.
The same is true of the date list, so this too would work with the dates entered into a column that will be hidden, then copied into a visible column with a formula that introduced a detectable difference into the copied version, dependent on the weekday of each date. That difference would be used to trigger the conditional formatting of the cell containing the calculated date as text value. See the example below.
But the (scheduled) Movie Title column doesn't fit nicely into that mode of operation, as it is edited quite often. As editing, usng the model described, requires making the data column visible, editing the entry (or entries) in that column, then rehiding the column, the hassle factor soon becomes insufferable, if nothing else.
The first solution I considered (see earlier reply) is workable only if the the formatted table starts and remains the same size in all details (ie. individual row height) as the main table.Any change in row height in the main table not reflected in the auxiliary table immediately destroys the impression of formatting applying to the correct cells. With cells set to wrap text and varying lengths of movie titles, wrapped lines changing the height of individual rows is pretty much unavoidable.
Best practice here would seem to be to use a separate column to flag the titles already in the "Class" list with a "√" (or flag those not in the list with an "X"), and use conditional formatting to change the background colour of the flagging cell.
Here's a sample, using "W" to flag the weekend dates in the new column B, and "√" to flag the titles that are on the list already in the new column D.
I've added two titles to the weekend date, November 18. One is non-existent (as far as I know), so it doesn't appear in the list and doesn't get flagged; the other is chosen from a visible part of the list to show the highlighting of the title in that list. Column "C" (now column "F" due to the insertion of two new columns) is hidden. G, labelled .Class, is the calculated column (D) from the previous message.
Regards,
Barry -
Spry js for dynamically naming file based on day names..but wait theres more!
Hi,
I'm creating a program guide for a tv station based on xmls, so I'm wanting to creating a data set that calls a file name "sunday.xml" on a Sunday
and feed that into the var section in the header that calls the file for that data set-see the red bit.
example:
var dailypg = new Spry.Data.XMLDataSet("xml/sunday.xml" , "EPG/Service/Event");
I hope that made sense.
The problem is that I don't know how to write js-well i wrote a script that spits out the right name, the "var filename = etc... bit,
example:
var day = new Date()
var weekday=new Array(7);
weekday[0]="sunday";
weekday[1]="monday";
weekday[2]="tuesday";
weekday[3]="wednesday";
weekday[4]="thursday";
weekday[5]="friday";
weekday[6]="saturday";
var filename = (weekday[day.getDay()]);
but I don't know how to feed the var "filename" into where it sets the file name for the xml. Is anyone able to point me in the right direction?
Thanks.I am doing something very similar.
var aid = 6882
var HotelDetails2 = new Spry.Data.XMLDataSet("http://xmlfeed.****.com/index.aspx?aid=" + aid + "&rtype=3&hids=100652", "hotel_search/hotel");
This works but have had great trouble with the wizard. As soon as I make it dynamic then it breaks the wizard, which I would like to use. I have tried having a line commented out which is unmodified so I can switch between the two but that really confuses it.
Just in case you were wondering I will be getting around to getting aid from a querystring but not there yet.
Any ideas, it can't be all that hard to do this surely and feel I must be missing something.
Thanks,
Steve. -
Selecting records based on month and year parameters
Hi. I have a sql 2008 r2 stored procedure which needs modifying to return the data based on a start / end month and year.
It's a large SP so I'll summarise - It accepts four parameters:
@StartMonth NVARCHAR(10)
@StartYear NVARCHAR(4)
@EndMonth NVARCHAR(10)
@EndYear NVARCHAR(4)
The current WHERE clause is:
WHERE ta.TimeByDay BETWEEN '01' + '-' + ltrim(LEFT(@StartMonth, 3)) + '-' + @StartYear
AND convert(nvarchar,datediff(day, ta.TimeByDay, dateadd(month, 1, ta.TimeByDay))) + '-' + ltrim(LEFT(@EndMonth, 3)) + '-' + @EndYear
Example of input parameters:
@StartMonth = N'January',
@StartYear = N'2014',
@EndMonth = N'February',
@EndYear = N'2014',
Result:
The conversion of a nvarchar data type to a datetime data type resulted in an out-of-range value.
(1 row(s) affected)
However it executes correctly if we do either of the following:
1) Run the SQL direct in QA and type in January and February rather than passing in the Start/End Month parameters
2) As you can see we use the following datediff call to get the number of days per month. IF I replace this with '28', or '31' for example the query also runs (oddly number 1 above then also runs by executing the SP):
convert(nvarchar,datediff(day, ta.TimeByDay, dateadd(month, 1, ta.TimeByDay)))
How do I update the WHERE clause to return records between a start/end month and year?
I'm a day on this so any help appreciated.
Thankscreate function NthDayOfMonth (@year int, @month smallint, @weekday varchar(15), @nth smallint)
returns datetime
as
begin
declare @the_date datetime, @c_date datetime, @cth smallint
set @cth = 0
set @c_date = convert(varchar,@year)+'-'+convert(varchar,@month)+'-01'
while month(@c_date) = @month
begin
if datename(weekday,@c_date) = @weekday set @cth = @cth + 1
if @cth = @nth and datename(weekday,@c_date) = @weekday set @the_date = @c_date
set @c_date = dateadd(day,1,@c_date)
end
return @the_date
end
go
create function Dates(@date datetime)
returns @table table
now datetime,
today datetime,
Month_start datetime,
Month_end datetime,
Prev_Month_Start datetime,
Prev_Month_End datetime,
Week_Start datetime,
Week_End datetime,
Prev_Week_Start datetime,
Prev_Week_End datetime,
Quarter_Start datetime,
Quarter_End datetime,
Prev_Quarter_Start datetime,
Prev_Quarter_End datetime,
Year_Start datetime,
Year_End datetime,
Prev_Year_Start datetime,
Prev_Year_End datetime,
Month_End_TS datetime,
Prev_Month_End_TS datetime,
Week_End_TS datetime,
Prev_Week_End_TS datetime,
Quarter_End_TS datetime,
Prev_Quarter_End_TS datetime,
Year_End_TS datetime,
Prev_Year_End_TS datetime,
Year smallint,
Month smallint,
Day smallint,
Month_Name varchar(15),
Day_Name varchar(15),
WD smallint
as
begin
if @date IS NULL set @date = getdate()
insert into @table
select
@date as now,
convert(datetime,convert(varchar,@date,101)) as today,
dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Month_Start,
dateadd(day,-1,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101))))) as Month_end,
dateadd(month,-1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_start,
dateadd(day,-1-day(@date)+1,convert(datetime,convert(varchar,@date,101))) as Prev_Month_End,
dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_Start,
dateadd(day,7-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Week_End,
dateadd(day,-6-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_Start,
dateadd(day,0-datepart(dw,@date),convert(datetime,convert(varchar,@date,101))) as Prev_Week_End,
convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01') as quarter_start,
dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01'))) as quarter_end,
convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01') as prev_quarter_start,
dateadd(day,-1,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01'))) as prev_quarter_end,
dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))) as Year_Start,
dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Year_End,
dateadd(year,-1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_Start,
dateadd(year,-1,dateadd(year,1,dateadd(day,0-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Prev_Year_End,
dateadd(ms,-3,dateadd(day,0,dateadd(month,1,dateadd(day,0-day(@date)+1,convert(datetime,convert(varchar,@date,101)))))) as Month_End_Ts,
dateadd(ms,-3,dateadd(day,-1-day(@date)+2,convert(datetime,convert(varchar,@date,101)))) as Prev_Month_End_TS,
dateadd(ms,-3,dateadd(day,8-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Week_End_TS,
dateadd(ms,-3,dateadd(day,1-datepart(dw,@date),convert(datetime,convert(varchar,@date,101)))) as Prev_Week_End_TS,
dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(@date)) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,@date)-1)*3)+1),2)+'-01')))) as quarter_end_TS,
dateadd(ms,-3,dateadd(day,0,dateadd(quarter,1,convert(datetime,convert(varchar,year(dateadd(quarter,-1,@date))) +'-'+ right('0'+convert(varchar,((datepart(QUARTER,dateadd(quarter,-1,@date))-1)*3)+1),2)+'-01')))) as prev_quarter_end_TS,
dateadd(ms,-3,dateadd(year,1,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101))))) as Year_End_TS,
dateadd(ms,-3,dateadd(day,1-day(@date),dateadd(month,1-month(@date),convert(varchar,@date,101)))) as Prev_Year_End_TS,
Year(@date) as Year,
Month(@date) as Month,
Day(@Date) as Day,
datename(month,@Date) as Month_Name,
datename(WEEKDAY,@date) as Day_Name,
datepart(weekday,@date) as WD
return
end
go
create function Holidays(@year smallint)
returns @table table
date datetime,
type varchar(10),
name varchar(25)
as
begin
insert into @table
select convert(datetime,convert(varchar,@year)+'-01-01') as date,'Holiday' as type ,'New Years Day' as name UNION ALL
select dbo.NthDayOfMonth(@year,2, 'Monday',3),'Holiday','Family Day' UNION ALL
select dateadd(d,0-case when datepart(weekday,convert(varchar,@year)+'-05-25') in (1,2) then 5+datepart(weekday,convert(varchar,@year)+'-05-25') else datepart(weekday,convert(varchar,@year)+'-05-25')-1 end, convert(varchar,@year)+'-05-25') ,'Holiday','Victoria Day' UNION ALL
select convert(varchar,@year)+'-01-07' ,'Holiday','Canada Day' UNION ALL
select dbo.NthDayOfMonth(@year,8, 'Monday',1),'Holiday','Civic Holiday' UNION ALL
select dbo.NthDayOfMonth(@year,9, 'Monday',1),'Holiday','Labour Day' UNION ALL
select dbo.NthDayofMonth(@year,10,'Monday',2),'Holiday','Thanksgiving' UNION ALL
select convert(varchar,@year)+'-11-11' ,'Holiday','Rememberance Day'UNION ALL
select convert(varchar,@year)+'-12-25' ,'Holiday','Christmas Day' UNION ALL
select convert(varchar,@year)+'-12-26' ,'Holiday','Boxing Day'
update @table
set date =
case when name != 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
when name != 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,1,date)
when name = 'Boxing Day' and datepart(weekday,date) = 7 then dateadd(day,2,date)
when name = 'Boxing Day' and datepart(weekday,date) = 1 then dateadd(day,2,date)
when name = 'Boxing Day' and datepart(weekday,date) = 2 then dateadd(day,1,date)
else date
end
return
end
go
Using these functions (in place of a calendar table) you could do something like this:
DECLARE @forumTable TABLE (sales MONEY, saleDate DATE)
INSERT INTO @forumTable (sales, saleDate)
VALUES
(123.45, '2014-01-05'),(678.90, '2014-01-06'),(111.21, '2014-01-07'),(314.15, '2014-01-08'),(161.71, '2014-01-09'),
(819.20, '2014-02-05'),(212.22, '2014-02-06'),(324.25, '2014-02-07'),(262.72, '2014-02-08'),(829.30, '2014-02-09')
SELECT SUM(f.sales), d.month_end
FROM @forumTable f
CROSS APPLY sandbox.dbo.dates(f.saleDate) d
GROUP BY d.month_end -
Error using WEEKDAY function in view filter
I want to be able to display all events in a calendar for the following week (Saturday to Saturday). I have created a column called week_end that is a calculated column and gives the date of the Saturday after the event:
=[Start Time]+(7-WEEKDAY([Start Time]))
I then want to use a filter based on Today as follows:
Show only items when week_end is greater than
[Today]+(7-WEEKDAY([Today]))
and less than
[Today]+(7-WEEKDAY([Today]))+7
However I get the error: Filter value is not in a supported date format
Any ideas what the problem is? I seem to be able to do things like [Today]+3, but I want the view to be from Saturday to Saturday regardless of what day I look at it.
Thanks
KateHi,
According to your post, my understanding is that you wanted to display all events in a calendar for the following week (Saturday to Saturday).
You can't use complex formula in Filters - you have to keep it simple like [Today]-30 for last 30 days.
The solution is to turn the problem on its head and add calculated columns to work out the start of the week and the end of the week then filter when the current date is between those dates (i.e. Start <= [Today] AND End >= [Today])
Please follow the steps as below to achieve what you want:
Create a “WeekStart” calculated column, select “Date and Time” as a data type returned by the formula:
=[Start Time]-WEEKDAY([Start Time])
Create a “WeekEnd” calculated column, select “Date and Time” as a data type returned by the formula:
=WeekStart+7
Create a “PerWeekStart” calculated column, select “Date and Time” as a data type returned by the formula:
=WeekStart-7
Modify view, show items only when the following is true:
PreWeekStart is less than or equal to [Today]
And
WeekStart is greater than [Today]
5. Open the view, it will
display all events in a calendar for the following week.
Generally, the week goes Sunday to Saturday. If you want to display all events in a calendar for the following week (Sunday to Saturday), you need to modify the calculated column:
WeekStart: =[Start Time]-WEEKDAY([Start Time])+1
WeekEnd: =WeekStart+6
Here are two similar threads for you to take a look at:
http://blog.pentalogic.net/2012/09/complete-guide-to-filtering-sharepoint-lists-by-the-current-week/
http://rehmangul.wordpress.com/2010/10/06/filter-views-based-on-a-week/
Best Regards,
Linda Li
Linda Li
TechNet Community Support -
Incorrect results for calculation based on diff dimensions - 11.1.1.5
Hello All,
OBIEE gives incorrect results when i try to perform a calculation (for eg: addition) based on 2 measures. For eg:
(Note: "->" signifies 1:M)
Rpd (Physical model & BMM): dim_fe -> dim_gl-> Fact_Legder <- Dim_param
Fact_Ledger (agg measures) -> YTD_01, YTD_02...... YTD_12 ( here 01,02...12 represent month i.e. if "Feb" selected in prompt then we need to use YTD_02 and so on for other months)
Answers: Created a report with following columns
Column Name : Formula
=================
Line Item : 'Net Profit'
Prev Yr Act: (filter("Fact Ledger"."YTD_12" using "Fact_Ledger"."YEAR"=@{pYear}{2013}-1 and "Dim_Param"."PL_Line" in ( 'Item 1','Item 2','Item 3') and "Fact_Ledger"."Code"=100)/1000) /
(filter("Fact Ledger"."YTD_12" using "Fact_Ledger"."YEAR"=@{pYear}{2013}-1 and "Dim_FE"."Item" in ( 'L1','L2','L3') and "Fact_Ledger"."Code"=100)/1000)
Curr Yr Act: (filter("Fact Ledger"."YTD_12" using "Fact_Ledger"."YEAR"=@{pYear}{2013} and "Dim_Param"."PL_Line" in ( 'Item 1','Item 2','Item 3') and "Fact_Ledger"."Code"=100)/1000) /
(filter("Fact Ledger"."YTD_12" using "Fact_Ledger"."YEAR"=@{pYear}{2013} and "Dim_FE"."Item" in ( 'L1','L2','L3') and "Fact_Ledger"."Code"=100)/1000)
Curr Yr Plan: case when '@{pmonth}{Jan}='Jan' then
(filter("Fact Ledger"."YTD_01" using "Fact_Ledger"."YEAR"=@{pYear}{2013} and "Dim_Param"."PL_Line" in ( 'Item 1','Item 2','Item 3') and "Fact_Ledger"."Code"=200)/1000)/
(filter("Fact Ledger"."YTD_01" using "Fact_Ledger"."YEAR"=@{pYear}{2013} and "Dim_FE"."Item" in ( 'L1','L2','L3') and "Fact_Ledger"."Code"=200)/1000)
when '@{pmonth}{Jan}='Feb' then
(filter("Fact Ledger"."YTD_02" using "Fact_Ledger"."YEAR"=@{pYear}{2013} and "Dim_Param"."PL_Line" in ( 'Item 1','Item 2','Item 3') and "Fact_Ledger"."Code"=200)/1000)/
(filter("Fact Ledger"."YTD_02" using "Fact_Ledger"."YEAR"=@{pYear}{2013} and "Dim_FE"."Item" in ( 'L1','L2','L3') and "Fact_Ledger"."Code"=200)/1000)
when '@{pmonth}{Jan}='Dec' then
(filter("Fact Ledger"."YTD_12" using "Fact_Ledger"."YEAR"=@{pYear}{2013} and "Dim_Param"."PL_Line" in ( 'Item 1','Item 2','Item 3') and "Fact_Ledger"."Code"=200)/1000)/
(filter("Fact Ledger"."YTD_12" using "Fact_Ledger"."YEAR"=@{pYear}{2013} and "Dim_FE"."Item" in ( 'L1','L2','L3') and "Fact_Ledger"."Code"=200)/1000)
endthe results are incorrect. Any help appreciated.
Qry generated is like
(select...
case when year=.. and pl_lin=... and code=100 then ytd_01,
case when year=.. and pl_lin=... and code=100 then ytd_03,
case when year=.. and pl_lin=... and code=100 then ytd_04,....,
case when year=.. and pl_lin=... and code=200 then ytd_01,
case when year=.. and pl_lin=... and code=200 then ytd_03,
case when year=.. and pl_lin=... and code=200 then ytd_04,....,
from...
where ... year in (2013-1,2013) and pl_line('Item1,'Item2','Item3') or fe.item('l1','l2','l3') and code in (100,200)... ) D1
(select
case when 'Apr'='Jan' thne d1.c1 when 'Apr'='Feb' then d1.c2......
from D1
Regards..
ShrutiSee if this explains it better for my crosstab with page items of Vendor Number 1234.
Vendor 1234
Dc Nbr 1 2 4 AAAA
Sum Invoice Amt 1387.04 300.82 327.29 2015.15
Sum Cost 44.86 57.43 25.54 127.83
Sum Advanced Cost 102.44 0 0 102.44
Sum Consolidation Cost 30.37 0 0 30.37
Sum Allowance Amt 27.74 6.02 6.54 40.30
Net Freight Cost 149.93 51.41 19 220.34
Freight Percent 10.81 17.09 5.81 ****
As stated before, Frieght Percent is a calculation I created in Discoverer that looks like this :
( NVL(Sum Cost,0)+NVL(Sum Advanced Cost,0)+NVL(Sum Consolidation Cost,0)-NVL(Sum Allowance Amt,0) )/NVL(Sum Invoice Amt,0)*100
Column AAAA was created in Discoverer using Sum of field and show to the right.
What I need is for the **** to be the correct calculation for the totals in column AAAA. If I use do a total for Freight Percent using the Cell Sum I get 33.70., what I want is it to be 10.93, which is (127.83 + 102.44 + 30.37 - 40.30)/2015.15*100.
If I use an Average Total row for Freight Percent, I get 11.24 which is 33.70 / 3 (the 3 would be the # of dc nbr's)
I did start with using the detail level data to create this crosstab. Then I made a new version and used the SUM data. I seem to get the same results but am still having issues with the one **** value.
Hopefully this explains it better.
Thanks for the ideas so far. -
Conditional Processing based on month and Year
Hi ALL,
I have one package that Contain two DataFlow
DFT1
DFT2
now What I need ,I need to Process the DFT1 on every week and DFT2 on every month Start.
Please Help Me .
How can I do this task.
ThanksHi BI_group,
The two Data Flow Tasks should not be connected, right? We can add two Execute SQL Tasks to store the day or weekday of today in a variable, connect them with the two Data Flow Tasks respectively, and configure Precedence Constraint based an expression.
For example, we configure Execute SQL Task 1 as follows:
On “General” tab:
ResultSet: Single row
ConnectionType: OLE DB
Connection: (Any OLE DB connection manager)
SQLStatement: SELECT DATENAME(WEEKDAY,GETDATE()) AS TodayOfWeekday
On “Result Set” tab:
Result Name: 0
Variable: User::TodayOfWeekday
Then, double click the path between Execute SQL Task 1 and Data Flow Task 1, and configure the Precedence Constraint as follows:
Evaluation operation: Expression
Expression: @[User::TodayOfWeekday]=”Sunday”
For Execute SQL Task 2, you can use the query “SELECT DAY(GETDATE()) AS TodayOfMonth” to get the month day of today, store it in the variable TodayOfMonth, and configure the expression of the Precedence Constraint between Execute SQL Task 2 and Data Flow
Task 2 as:
@[User::TodayOfMonth]="1"
Regards,
Mike Yin
TechNet Community Support -
Hi,
How can we show details and group by week number for a set of data when the custom week begins Saturday and ends Friday?
For example, the table has data as follows:
Date Hrs Weekday
12/01/2007 8 Saturday
12/02/2007 8 Sunday
12/03/2007 11 Monday
12/04/2007 0 Tuesday
12/05/2007 9 Wednesday
12/06/2007 8 Thursday
12/07/2007 8 Friday
12/08/2007 8 Saturday
12/09/2007 9 Sunday
12/10/2007 8 Monday
12/11/2007 0 Tuesday
12/12/2007 0 Wednesday
12/13/2007 12 Thursday
12/14/2007 8 Friday
12/15/2007 9 Saturday
In Oracle Reports, if I group it by week number using
to_char(to_date(:p_date,'DD-MON-RRRR'),'WW') within the query, I get the week no of the year and begins from Monady of the date range.
So it gives my summary like
Week1 16
Week2 53
Week3 37
I wanted the report to show it as
Week1 52 (from 12/01/2007 to 12/07/2007)
Week2 45 (from 12/08/2007 to 12/14/2007)
Week3 9 (for 12/15/2007 and beyond ...
Can someone shed some light on how to achieve it without using any temporary table and within the SQL quey for use in Oracle Reports?
Your valuable inputs is very much appreciated.
Thanks
udsThanks for the inputs. I appreciate that. This solution does not serve my purpose and so had to define a small function to accept the reporting date and return the week number of the year after having jacked up as required. Here is the function:
CREATE OR REPLACE FUNCTION fn_user_otl_week_no (
p_start_time IN DATE )
RETURN NUMBER
IS
l_week_no NUMBER;
l_weekday CHAR (30);
BEGIN
SELECT TO_CHAR (TO_DATE (p_start_time, 'DD-MON-RRRR'), 'DAY'),
TO_NUMBER (TO_CHAR (TO_DATE (p_start_time, 'DD-MON-RRRR'), 'WW'))
INTO l_weekday,
l_week_no
FROM DUAL;
IF l_weekday = 'SATURDAY'
THEN
l_week_no := l_week_no + 1;
ELSIF l_weekday = 'SUNDAY'
THEN
l_week_no := l_week_no + 1;
END IF;
RETURN (l_week_no);
EXCEPTION
WHEN OTHERS
THEN
RETURN (0);
END;
In my query, I can send in a date and get back the week of year. The code is self explanatory. The following qry
select to_char(to_date('08-DEC-2007','DD-MON-RRRR'),'WW') wk_of_yr,
gn_otl_week_no('08-DEC-2007') wk_bump from dual
yielded
49 50
For '10-DEC-2007' it yielded
50 50
This is what I had wanted. By this I can group the hrs logged and sum it up for the week from Saturday to the following Friday.
Thanks for all the inputs.
One caveat I faced was that the return value did not get incremented if I declared the variable l_weekday as VARCHAR2(30). But works fine if declared as CHAR(30). Well, this could be some issue with VARCHAR2 vs CHAR; a whole different ballgame altogether.
Thanks
uds
Maybe you are looking for
-
Error while extracting data using function module
Hello, I created one generic datasource and i want to extract data with the option "Extraction by Function Module". But when i specified function module name and was trying to save, it thrown a error message saying 'The specified table does not exist
-
Explain plan for Query performance
Hi Gurus, I need to improve the performance of a procedure. The procedure has the below QUery. I dont have Idea on how to imrpove the perf by seeing the explain plan. Can anyone please help me to explain where I need to change the code. The below are
-
No equipment or serial no. in manual inspection lot
Hi All, I have maintained 2 user status servicable & unservicable for my serialized equipments in refurbishment processing. In the process after work completed when I move the material to quality and create the manual inspection lot thru qa01 and don
-
Controlling PPT animation timing in Captivate 4
I imported a PPT to Captivate. I want to control the timing of the PPT animations, but each object just comes in quickly - one after another. Is there a way to control this and have each object come in when I want it to? Thanks, Howie
-
Porting application from jboss to glassfish
I am involved in a project where I need to upgrade an application to a better application server. It is currently running on jboss 4.01. It has been suggested that I consider porting the app, which includes EJB, JSF, and Web Services to glassfish. Do