I have a report created in SSRS with 2 parameters "First Start Time" and "Last End Time" in SQL the fields that I'm using for the data set is Tm_TimeDisplay (Ex. 12:00 AM, 1:00 PM ext) and Tm_TimeKey (Ex. 0, 30 ect.). Then I am calling a stored procdure to pull data.
I can display the Tm_TimeDisplay in the parameter dropdown, but how can I use the value of Tm_TimeKey to pull data in a table?
For example: First Start Time: 12:00 PM (field: Tm_TimeDisplay), Last Start Time: 12:30 PM (field: Tm_TimeDisplay), the value that should be used to pull data in SQL are (0,30) (field: Tm_TimeKey)?
Related
I'm searching for a formula to have a value of a variable xxxxx only when the date is higher than '2020-07-17'.
I have tried many options, but none work so far.
case when Date>20200717 then xxxxx
end
case when Date>'2020-07-17' then xxxxx
end
I also tried formulas with REGEXP_MATCH
case when REGEXP_MATCH(Date, '2017-07-1[0-9]') then xxxxx
end
My Date is a "Date (YYYYMMDD)"
0) Summary
Use EITHER #1: New Recommended approach as per the 17 Sep 2020 Date and Time Update;
OR #2: The original suggestion, prior to the 17 Sep 2020 Date and Time Update.
1) Recommended Suggestion (Using the 17 Sep 2020 Date and Time Update fields)
The single Calculated Field below creates a Text Date field using FORMAT_DATETIME function, then the CAST function to ensure that the Type is set to Number, after which values matching 20200717 (17 Jul 2020) display values of the ifr_ds_PV field while other values (not matching 20200717) are treated as NULL:
CASE
WHEN CAST(FORMAT_DATETIME("%Y%m%d", Date) AS NUMBER ) > 20200717 THEN ifr_ds_PV
ELSE NULL
END
Added a New Page to the Editable Google Data Studio Report and a GIF to demonstrate:
2) Original Suggestion (Using the pre 17 Sep 2020 Date and Time Update fields)
2.1) dateNumber
It can be achieved by first creating a Date Number field at the Data Source; create the Calculated Field below and ensure that the Type is set to Numeric > Number:
CAST(Date AS NUMBER)
GIF to visualise the process:
2.2) Calculated Field(s)
The Calculated Fields can then be adapted by using the newly created Date# field (which follows the YYYYMMDD format), for example:
CASE
WHEN dateNumber > 20200717 THEN ifr_ds_PV
ELSE NULL
END
Google Data Studio Report and a GIF to elaborate:
Create a calculated field _Date as:
CAST(FORMAT_DATETIME("%Y%m%d", Date) AS NUMBER )
and make sure it can be used as a metric.
Then use that to build the CASE statement, lie this:
CASE
WHEN LAST(_Date) > 20200717 THEN xxx
ELSE yyyy
END
I have a report and the report StartDate and EndDate parameters are using the expression as a default value below.
=DateAdd(DateInterval.Minute,0,DateAdd("h",7,DateAdd("h",-24,Today())))
=DateAdd(DateInterval.Minute,0,DateAdd("h",7,Today()))
When I execute the report, the report is starting from the day before at 7 AM to today 7 AM.
I would like to keep the report Start time and End time like this(07:00).
I also want to send the report to customer every day 7:30 AM but the report needs to be executed according to start date and end date paramaters.
Example: today 12.12.2019
Subscription time will be 07:30 AM
report needs to be running this time:
StartDate : 11/12/2019 07:00:00
EndDate : 12/12/2019 07:00:00
But when I schedule subscription every day and 7:30 AM, I received report from one day before 7:30 AM and today 7:30 AM.
I just want to see report from 7:00am to 7 am. Even if I change schedule time.
Could you please help me about this problem. How can I edit my subscription?
Is it possible to write an expression in "date/time from - date/time to" fields in subscription?
Btw, When I unclick “use Default” part, it always takes 11-12-2019 even 2 days after ☹
Time from needs to be one day before at 07:00 AM
Time to should be on that day at 07:00 AM
Do you have any suggestion for it?
Thanks
I resolved my issue. There are 2 solutions for it.
Option 1 :
In the report design If it is must to have those date parameters must be DATTEIME and to allow TIME factor as well then and if you want to run the report which is subscribed always for Yesterday 7:00 to today 7:00 am then I would not rely on sending any parameter values based on expressions …I would set up Date/Time Parameter in report design to allow null values and send null values as default from the subscription settings.
Then In report SP you can always add a clause at the TOP like
if #startDateTime is null AND #endDateTime is null
begin
set #startDateTime =CONVERT(VARCHAR(10), getdate(), 111);
set #startDateTime =dateadd(hh,7,( dateadd(d,-1,#startDateTime)))
set #endDateTime =dateadd(d,1,#startDateTime)
end
and let the rest SP be same
Option 2 :
If you can change the report parameters to be a type only DATE then its easy always send =Today() in your subscription parameter for both Start & End
Then In report SP you can always add a clause at the TOP like
if #startDateTime = #endDateTime
begin
set #endDateTime =CONVERT(VARCHAR(10), #endDateTime, 111);
set #endDateTime =dateadd(hh,7,#endDateTime)
set #startDateTime =dateadd(d,-1,#startDateTime)
end
and let the rest SP be same
Option 2 is better if they are ok to have Start & End date parameter as just DATE instead of DATETIME.
Any way Using any of these options do handle this in SP… you can always have control in future if they want to change time form 7:00 am to any other time …no need to change report design just update SP…2 minutes
You can schedule this report for any time of the day and it will always send them a report for Yesterday 7:00 to Today 7:00
I have a SSIS Package and I need to schedule it to run at 1:00 AM and 1:00 PM every day.
At 1:00 AM it should pass parameters of the previous day for e.g.
15 Nov 2018 12:00 PM as #StartDate & 15 Nov 2018 11:59 PM as #EndDate
At 1:00 PM it should pass parameters of the current day for e.g.
15 Nov 12:00 AM as #StartDate & 15 Nov 11:59 AM as #EndDate
A stored procedure is called through an OLE DB Source Editor task in Data Flow.
Does anyone have any suggestions that How I could achieve this noting the fact that if the job fails at 1:00 PM & it should re-run at 2:00 PM, it should still pass the same parameters.
Here are the steps to pass the date parameters to OLEDB task.
Have start date & end date parameters in (I suppose you must be having).
Assign the dates values to both parameters using SQL task.
Pass these parameters to OLDEB stored procedure to data flow task.
For scheduling:
Create two different jobs for each run, one for 1 AM & another for 2 AM of the job.
For second job run, implement the following steps.
Create a table which log the job execution status with date and time. That table has insertion after each run of the job.
When second job schedule execute first check log table in first step and check the last run status of the job.
If it was successful exit else go to next step.
Hope this will help.
My string dates are as follows in YYYYMM format:
201008
201009
201010
201011
201012
...
The following is my CONVERT statement in my stored procedure:
CONVERT (datetime, #FileName + '01', 112)
my results are showing up fine in SQL-Server as follows
2010-10-01
2010-11-01
2010-12-01
...
However, in MS Dynamics CRM they are showing up as the last day a month earlier (corresponding with the previous SQL-Server results) as follows:
9/30/2010
10/31/2010
11/30/2010
...
What the heck is going on here?
You always have to remember that CRM stores the dates in UTC, but displays them as the users's timezone:
So for your example, when you're working in SQL the Date Time is in UTC, but when you look at CRM it's in your local time.
Refer to the following thread:
http://social.microsoft.com/Forums/en-US/84074c91-4421-4544-83a7-c6eea28a39e9/crm-displays-different-date-than-stored-in-db?forum=crm
I have a PostgreSQL table with the following schema -
CREATE TABLE test (
id serial NOT NULL PRIMARY KEY,
username varchar(100) NOT NULL, -- The user name
dob timestamp with time zone NOT NULL -- The date of birth
);
I then inserted some data into the table with data like this -
INSERT INTO "test" ("username", "dob") VALUES (E'Scotty', E'2009-05-14 15:44:43');
And if I check the DB for the data, I get this -
mydb=> select username, dob from test where username='Scotty';
username | dob
----------+---------------------------
Scotty | 2009-05-14 15:44:43+05:30
(1 row)
Everything is fine and dandy until I try inserting some data with the date before 1946 -
INSERT INTO "test" ("username", "dob") VALUES (E'James T Kirk', E'1945-01-01 11:30:11');
mydb=> select username, dob from test where username='James T Kirk';
username | dob
-------------- +---------------------------
James T Kirk | 1945-01-01 11:30:11+06:30
(1 row)
Look at the above result. Notice how the Timezone value has changed from +05:30 to +06:30
It actually gets worse when I insert any date which is before 1942 -
INSERT INTO "test" ("username", "dob") VALUES (E'Spock', E'1941-01-01 11:30:11');
mydb=> select username, dob from test where username='Spock';
username | dob
----------+------------------------------
Spock | 1941-01-01 11:30:11+05:53:20
(1 row)
Now the Timezone value has got completely mangled and the date can't be parsed.
I would appreciate any help with this.
My Timezone is Asia/Kolkata (GMT+05:30).
Update: I tried entering the data by specifying the TZ explicitly like this -
INSERT INTO "test" ("username", "dob") VALUES (E'McCoy', E'1941-01-25 00:20:30+05:30');
Even then it didn't work.
mydb=> select username, dob from test where username='McCoy';
username | dob
----------+------------------------------
McCoy | 1941-01-25 00:43:50+05:53:20
(1 row)
What locale are you in? Probably PostgreSQL is assuming that the dates are for your current locale, and applying appropriate time zone and DST rules, which isn't the right thing to do if the dates and times are (say) UTC.
Do you really need the timezone functionality? A timestamp without time zone will exhibit saner behavior, since it doesn't have to implement weird rules. But if you need the time zone, then you definitely want to fix this rather than kludge it.
The best fix is just to specify the timezone explicitly: '04:05:06-08:00' for GMT–08:00, or perhaps '04:05:06z' for GMT/UTC/"Zulu" (hence the 'z').
Edit: Most of the real weirdness is coming from the Asia/Kolkata time zone. From tzdata2009g:
# India
# Zone NAME GMTOFF RULES FORMAT [UNTIL]
Zone Asia/Kolkata 5:53:28 - LMT 1880 # Kolkata
5:53:20 - HMT 1941 Oct # Howrah Mean Time?
6:30 - BURT 1942 May 15 # Burma Time
5:30 - IST 1942 Sep
5:30 1:00 IST 1945 Oct 15
5:30 - IST
You don't describe what you expect the behavior to be, so it's hard to say where you want to go from here.
This looks like a Daylight Saving issue. (From what I get, the timezone is UTC+05.30, DST sets in around March/April, and adds one hour).
Have you tried with inserting the same date and just changing the year to rule out that possibility?
For that last one, It's strange. I have not managed to reproduce it, but it could be because of the half hour zones. Is it the same if you change the TZ environment variable?
I have one similar but different problem.
We have PostgreSQL8.0 installed on WinXP.
One of the columns is of type
TimeStamp with TimeZone. The Time
value of this column changes with
the change in system time zone. Can
we avoid this?
After every retrieval
from table, half hour is getting to
thid column for every tuple.
I haven'nt been able to trace origin to this problem.
rgds
nithin