I have this simple SQL query which SELECTs the fields according to the criteria in WHERE clause. SELECT callingPartyNumber, originalCalledPartyNumber, finalCalledPartyNumber,
dateadd(ss, (dateTimeConnect + (60 * 60 * -5))+3600 , '01-01-1970 00:00:00') AS dateTimeConnect,
dateadd(ss, (dateTimeDisconnect + (60 * 60 * -5))+3600, '01-01-1970 00:00:00') AS dateTimeDisconnect,
CONVERT(char(8), DATEADD(second, duration, '0:00:00'), 108) AS duration
FROM Calls
WHERE
(callingPartyNumber = ISNULL(@callingPartyNumber, callingPartyNumber)) AND
(originalCalledPartyNumber = ISNULL(@originalCalledPartyNumber, originalCalledPartyNumber)) AND
(finalCalledPartyNumber = ISNULL(@finalCalledPartyNumber, finalCalledPartyNumber)) AND
(duration >= @theDuration) AND
((datetimeConnect - 14400) >= ISNULL(convert(bigint,
datediff(ss, '01-01-1970 00:00:00', @dateTimeConnect)), datetimeConnect)) AND
((dateTimeDisconnect - 14400) <= ISNULL(convert(bigint,
datediff(ss, '01-01-1970 00:00:00', @dateTimeDisconnect)), dateTimeDisconnect))
If you notice, in the SELECT, I add 3600 (1 hour) to adjust the time according to the current DayLight saving setting. Similarly, while comparing in WHERE clause, I subtract 14400 seconds (4 hours) to adjust the comparison according to EST (-5 GMT, but doing -4 GMT since daylight saving) and daylight saving.
Also, dateTimeConnect and dataTimeDisconnect fields save time in UTC seconds.
Now this application may be used by clients in different timezones. The application may be hosted on their server which would mean a different time zone. What would be the best way to make this time zone and daylight adjustment more dynamic instead of hardcoding the values.
I thought I would post this just in case you are not aware of the change of the Daylight Saving Time start and end dates in 2007. This is really an OS problem, not a SQL Server problem, but it could have a big impact on your applicaitons if you are not prepared. The first change is less that 2 months away, so it's not a bad time to give it some thought.
Here are some articles about preparing systems for the 2007 daylight savings time changes that you might find of interest.
Preparing for daylight saving time changes in 2007: “Starting in the spring of 2007, daylight saving time (DST) start and end dates for the United States will transition to comply with the Energy Policy Act of 2005. DST dates in the United States will start three weeks earlier (2:00 A.M. on the second Sunday in March) and will end one week later (2:00 A.M. on the first Sunday in November).
Microsoft will be producing an update for Microsoft products affected by the new United States daylight saving time transition dates. These updates will be released through a combination of channels including Microsoft Customer Support Services (CSS), hotfixes incorporated in Knowledge Base articles, Windows Update, Microsoft Update, Windows Server Update Services (WSUS), and the Microsoft Download Center.� http://www.microsoft.com/windows/timezone/dst2007.mspx
How to configure daylight saving time for the United States in 2007: http://support.microsoft.com/?kbid=914387
Daylight Saving Time in Canada: The article in the link below indicates that all Canadian provinces except for Nunavut have decided to follow the US daylight savings changes in 2007. The article contains links to news articles with official announcements of the changes. http://en.wikipedia.org/wiki/Time_in_Canada
Last weekend many of our severs had a failed job "collection_set_3_upload". The error that occured is: "Violation of PRIMARY KEY constraint 'PK_ active_ sessions_ and_requests'. Cannot insert duplicate key in object 'snapshots.active_sessions_and_requests'. The duplicate key value is (2824333, 2015-10-25 02:54:49.7630000 +02:00, 1)."Last weekend we happened to go from summer time to winter time. i.e. the clock passed 02:00 - 3:00 two times during this night.
I.e. there is a bug in the Data Collector component that collects data for the Management Data Warehouse: it uses local time instead of UTC. I've created a Connect item to report it to Microsoft.URL...how do you get your process running again? the job will no longer run because it will every 5 minutes keep on trying to upload the conflicting data for the 2nd 2:00 - 3:00 period. I've only found one solution: get rid of all data collected but not yet uploaded.
You do this by stopping the Collection set (in SSMS go to Object Explorer -> <the server you want to fix> -> Management -> Data Collection -> System Data Collection Sets. Right click "Query Statistics" and select "Stop Data Collection Set").Then you delete the cached results from the sql server machine's harddisk. These cached results are in files located in a Temp folder on the sql machine itself, inside the AppData folder for the service account SQL Server Agent is running under. Usually it will be something like: c:Users<sql agent service account>AppDataLocalTemp.
Inside this folder delete all files that have 'QueryActivity' in their name. You'll loose all data collected since the start of wintertime, but at least your data collection process will work again.After this you can start the Collection set again by right clicking it and select "Start Data Collection Set". Every 5 minutes the data will be summarised and uploaded into your management data warehouse.
Posting Data Etiquette - Jeff Moden Posting Performance Based Questions - Gail Shaw Hidden RBAR - Jeff Moden Cross Tabs and Pivots - Jeff Moden Catch-all queries - Gail Shaw
I am in need of a format string or simple vb code that can add the local time zone to the end of a time field.. Something like: 9:36 AM EST 9:36 AM PST
This timezone will just come from the machine that the reporting server is on. I don't see this listed as a standard format, and I have come up empty so far in my research - anyone got a solution for this?
I have the database on a GMT server and a logdate that is in GMT too. How do I convert this into CST (GMT -6) , during daylight savings (GMT-5) when passing it back to the webpage. I can use DATEADD(hh,-6,LogDate) but how do I know if the daylight savings period has started to do DATEADD(hh,-5,LogDate). I also want to solve this at the database level without altering the front-end. Thanks.
Hi Is their any function available in SQL SERVER like New_function() in Oracle. This function use to convert time from one Zone to another Zone. i.e Easter time zone to Pacific time Zone.
This must've been convered before, but I can seem to find a solution to it. Daylight Savings Time is about to end in my area, at which time the clocks will go backwards from 1:59am to 1:00am. I have scheduled jobs that run every minute, and I'm expecting that when the clock rolls back, they will stop running for the gained hour until the clock catches back up. So, I need an automated way to correct this.
I was looking at the msdb..sysjobschedules table, at the next_run_time column. But it doesn't make much sense. That value will periodically update, but it is always a good bit behind the next run time reported in EM. And manually updating it seems to have no effect. Is there a way to get a job to run or to recalculate the next run time via tsql script?
I apologize ahead of time if this has been covered. I tried searching but found only the OS specific response to my question (http://www.microsoft.com/windows/timezone/dst2007.mspx).
With the coming changes to DST in 2007, is there -- or is there even a need to -- patch either SQL Server 2005 or 2000 to account for those changes?
Finding Time Zone: Hi, 1. I have a patient record created in the database with a CreateDate 2. I need to find the time zone based on a state or city or zip in the record 3. And find corresponding EST time of CreateDate
I don't know what is going on, here's the error message, could someone please answer ? thanks
Server Error in '/' Application.
Procedure or Function 'aspnet_Membership_CreateUser' expects parameter '@TimeZoneAdjustment', which was not supplied.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Procedure or Function 'aspnet_Membership_CreateUser' expects parameter '@TimeZoneAdjustment', which was not supplied.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. Stack Trace:
After DST change (US/Canada), when I run any of my reports, I get this error:
"An internal error occurred on the report server. See the error log for more details. (rsInternalError) Get Online Help Specified argument was out of the range of valid values. Parameter name: date "
Hi All, Is there any function sql server to convert datetime zone. For example : EMEA follows GMT time zone. I want to convert time to other zones which are used by other geos like APAC,IJKK. Is there any utility on SQL server to do that?
I have been tasked with an interesting challenge and was wondering if any of you experts out there might have any ideas on a solution. Basically, I have a table of packages:
CREATE TABLE [dbo].[tPackage] ( [PkgID] [int] NOT NULL PRIMARY KEY CLUSTERED , [PkgDelivZip] [char] (5) COLLATE SQL_Latin1_General_CP1_CI_AS NULL , [PkgDelivDate] [smalldatetime] NULL , [HasBeenDeliv] [bit] NULL ) ON [PRIMARY] GO
INSERT INTO tPackage VALUES (1, '30022', '11/9/06 10:30 am', 1) INSERT INTO tPackage VALUES (2, '30022', '11/9/06 10:30 am', 0) INSERT INTO tPackage VALUES (3, '30022', '11/9/06 06:00 pm', 0) INSERT INTO tPackage VALUES (4, '96801', '11/9/06 10:30 am', 1) INSERT INTO tPackage VALUES (5, '96801', '11/9/06 10:30 am', 0) INSERT INTO tPackage VALUES (6, '96801', '11/9/06 06:00 pm', 0)
And I need to retrieve a list of those packages which are late for delivery. Now if location was not a factor, I could just use the simple script:
SELECT * FROM tPackage WHERE HasBeenDeliv = 0 AND PkgDelivDate < GetDate()
Unfortunately, in the case of package 5, it is not after 10:30am in Hawaii, so this should not be considered late. I thought about having a table of zipcodes with their timezone differential, but the really big problem comes in when you consider the areas which do not observe Daylight Savings Time.
Any thoughts? Thanks in advance for your feedback! Cat
I have used the GETDATE() function within an expression to create a directory name based on the current date. I am in the Sydney time zone and the new day's folder name doesn't change until after 11 am - so GETDATE() is picking up the date and not adjusting for the time zone. How do I either set the time zone within the package or make the GETDATE() function look at time zone of the system on which it is run?
How to insert a row number for a zone wise(ie group by zone column) in ssrs report in zone column  i should get zone1 only once (should not get Zone1,zone1, zone1 -3 times)
sl.no   Zone   District   no.of.region
1            hyd      24 2      ZONE1 chn      12 3            bang     2 1            raj       4 2      ZONE2  vizag    3 3            bbb     34
I created aspnet DB on SQL Server 2K using aspnet_regsql utility. Everything works fine except the DateTime fields in all tables are using a wrong time zone. How do I set it to use my local time zone? Any help will be greatly appreciated.
Most developers running SharePoint in integrated mode have been experincing issues when displaying SRS reports in a web site other than the default zone. There is a blog http://www.sharepointblogs.com/nrdev/archive/2007/06/21/ssrs-in-sharepoint-2007-site-using-forms-based-authentication-sharepoint-integrated-mode.aspx that explains that this is a bug and may be fixed when SP3 is released.
We are usi ng dual authentication for a particular site that hosts SRS reports and the default zone is windows auth and the internet zone is FBA. Since we cannot display reports using the RSViewerPage.aspx that comes with RS sharepoint addon, I decided to look for some way to display these reports in a non default zone. This method may help those experincing ths issue but the method assumes that you have one default zone or default zone [0] is the zone where reports are deployed from Visual Studio.
Here are the steps. 1. Go to your Layouts/reportseerver folder in your MOSS installation. 2. make a backup of RSViewerPage.aspx 3. Open RSViewerPage.aspx in visual studio and on the header declarations change the following line that looks like <%@ Page language="C#" Codebehind="RSViewerPage.aspx.cs" AutoEventWireup="false" Inherits="Microsoft.ReportingServices.SharePoint.UI.RSViewerPage,Microsoft.ReportingServices.SharePoint.UI.ServerPages,Version=9.0.242.0,Culture=neutral,PublicKeyToken=89845dcd8080cc91" %>
I have passed createdDate from UI to Stored procedure.createdDate field declared with DateTime.it is having value 2014-07-01.I need to fetch records from the database based upon the created field.but Create_TM in database having value Date with timestamp.so how would i change the createdfield in stored procedure.
ALTER PROCEDURE [dbo].[ByDateRange] @Feed VARCHAR(50), @CreatedDate DATETIME select * from Date_table where Create_TM = @CreatedDate
I am using Visual Web Developer 2005 Express Edition & SQL Server 2005 Express Edition.
In a database that is role-manager-enabled, you will have some tables like apsnet_Users, aspnet_Roles, etc. And some Columns like CreatedDate, LastLoginDate in the tables.
My problem: The datatime values in the aforementioned fields are updated based on GMT instead of the client's local time zone.
Is this the way it is? No matter true or not, how to fix it?
I've migrated a server with SQL Server 2008R2 and Reporting services into a new box with SQL Server 2014, but forgot to change the timezone to the correct one. I've changed it later, but it seems like the reports are running by the old default timezone. The schedule says that the report should run at 6:30am, but the Last Run column shows 8:30 PM.
I need to fix it without manually updating each subscription with some date/time conversion.
I have passed createdDate from UI to Stored procedure.createdDate field declared with DateTime.it is having value 2014-07-01.I need to fetch records from the database based upon the created field.but Create_TM in database having value Date with timestamp.so how would i change the createdfield in stored procedure.
ALTER PROCEDURE [dbo].[ByDateRange]
@Feed VARCHAR(50),
@CreatedDate DATETIME
select * from Date_table where Create_TM = @CreatedDate
I have a calendar control on a page that is saving the date to a SQL Server 2005 table and this works fine; but how do I also save it with the current time? It is always saving as 12:00:00 AM. Thanks for the help.
I'm trying to save times in datetime fields, but seem to have lots of issues with formats.
I'm using a multiline text box, where the user will pick from 09:00 09:30 10:00 etc, so the value that comes out in the .text property is "09:30"
Once I have that, whats the best way to convert this into the right format for a dt field? I understand it'll have todays date in it which is fine. It seems to work ok if I overwrite a textbox that's bound to a datetime field, but not if I'm sending it via an insert statement.
Also I'm using 24 hour format times, eg 14:00, do I need to do anything to ensure they're store in this format?
The following T-SQL code is run in a vb.net (2003) module.
I am acquiring data from an OPC server into an array of data type object. It is necessary to declare the array as an object for the OPC server to return data. The OPC returns the data in 15 mS.
I now need to save this data to a table in SQL 2005 running on a 2003 server.
The table for saving the data has already been created and saving the data is actually an 'update ... set ... where' statement.
The statement is For i as short = 1 to itemCount
sql_command = "Update [IO Log].[dbo].[IO Log] Set TagValue = " & itemValue(i) & " where TagName =' " & tagName(i) sql_command.executeNonQuery Next
The TagValue field datatype is decimal(18,6) The itemValue(i) datatype is object / variant. The itemValue array contains 95% values of type Single and the rest are Integers. The TagName datatype is varchar(50) The tagName(i) datatype is string
When I run the loop (255 iterations) with the above query it takes 1500 mS.
If I force a conversion by changing the query to sql_command = "Update [IO Log].[dbo].[IO Log] Set TagValue = Convert(decimal, " & itemValue(i) & ") where TagName =' " & tagName(i) it takes 900 mS to execute for 255 iterations.
I tried one more variation sql_command = "Update [IO Log].[dbo].[IO Log] Set TagValue = Convert(decimal(18,6), " & itemValue(i) & ") where TagName =' " & tagName(i) which takes 1200 mS to execute for 255 iterations.
If I use the following code dim tempValue as decimal = 123456789012.123456D sql_command = "Update [IO Log].[dbo].[IO Log] Set TagValue = " & tempValue & " where TagName =' " & tagName(i) it excutes in under 100 mS for 255 iterations.
There seems to be a problem during implicit / explicit conversion of type object/variant to decimal. I need to save the data received from the OPC (255 tags) in under 150 mS.
I want to save every query executed from a given software, let's say Multi Script for example, and save in a table query text, execution time and rows count among other possible useful information. Right now I've created a sp and a job that runs every 1 milliseconds but I can't figure out how to get execution time and rows count. Another problem with this is that if the query takes too long I end up with several rows in my table.
Can you point me in the correct direction in SQL2005 Server to adjust the SQL Server database collation case-insensitive, accent-sensitive, Kana-sensitive, and width-sensitive. We are trying to configure it to run with SharePoint Services.
Thanks in advance for any assistance that you might be able to provide.
Hi there, May be a kind of dumb question, but I have a multi-value parameter that I would like to give users the ability to select from in a SSRS 2005 Report and I was wondering if there was a way to adjust the width of the drop down so the user wouldn't have to scroll horizontally to see a full parameter item. It looks like it cuts off after about 30 characters.