In SQL Server 2008 R2 the function TODATETIMEOFFSET shows the following error:
The timezone provided to builtin function todatetimeoffset is invalid.
In some installations of SQL Server 2008 R2 the function works (same database and same code)
This is the code I’m using, it is part of a stored procedure:
-- table to contain every office timezone offset in minutes
DECLARE #mOfficeOffsetsT TABLE
(
[OfficeCode] VARCHAR(20) COLLATE SQL_Latin1_General_CP1_CI_AS primary key,
[OffsetMinutes] INT
);
INSERT INTO #mOfficeOffsetsT ([OfficeCode], [OffsetMinutes])
SELECT
[OfficeCode], [OffsetMinutes]
FROM
[dbo].[GetOfficeOffsets](); -- GetOfficeOffsets function get all offices offsets in minutes, for example: -180
DECLARE #mNow DATETIMEOFFSET;
SET #mNow = SYSDATETIMEOFFSET();
SELECT
NTF.[NotificationId],
NTF.[ScheduleDate],
NTF.[AppointmentId]
FROM
[Notification] NTF
INNER JOIN
[Appointment] AP ON NTF.[AppointmentId] = AP.[AppointmentId]
INNER JOIN
#mOfficeOffsetsT OO ON AP.[OfficeCode] = OO.[OfficeCode]
WHERE
TODATETIMEOFFSET(AP.[AppointmentDate], OO.[OffsetMinutes]) <= #mNow;
Notification table columns:
[NotificationId] [int] IDENTITY (1, 1) NOT NULL,
[ScheduleDate] [datetime] NOT NULL,
[AppointmentId] [int] NOT NULL,
.. other columns ..
Appointment table columns:
[AppointmentId] [int] IDENTITY (1, 1) NOT NULL ,
[OfficeCode] [varchar] (20) COLLATE SQL_Latin1_General_CP1_CI_AS NOT NULL ,
[AppointmentDate] [datetime] NOT NULL ,
.. other columns ..
My function “GetOfficeOffsets” doesn’t seem to be the problem, because if I hardcode #mOfficeOffsetsT table rows the error remains.
The data in the tables seem to be ok.
I have reproduced the error in:
SQL Server 2008 R2 RTM
SQL Server 2008 R2 SP1
SQL Server 2008 R2 SP2
SQL Server 2008 R2 SP3
SQL Server and database collation I'm using: SQL_Latin1_General_CP1_CI_AS
The OS does not seem to have influence:
Windows Server 2008 R2 Enterprise (production) >> get the error
Windows Server 2008 R2 Standard (testing) >> works well
Windows Server 2008 R2 Enterprise (dev) >> works well
Windows Server 2008 R2 Datacenter (dev) >> get the error
OS Region and Language settings does not seem to have influence.
Does anyone know what may be causing this strange error?
Related
We have some code try to create a temp table on SQL Server with the following:
CREATE TABLE #POM_read_expr_scratch2 ( auid VARCHAR(15) collate Latin1_General_BIN, aint_val INT ) ;
SELECT MAX(partition_number) FROM sys.partitions WHERE object_id = object_id( '#POM_READ_EXPR_SCRATCH2' ) HAVING MAX(partition_number) > 1;
CREATE UNIQUE INDEX re_scratch_index ON #POM_READ_EXPR_SCRATCH2 ( auid ) ;
COMMIT;
This code work with SQL Server 2016 Developer version. however when run with 2019 Standard version (DBMS VERSION:: 15.0.2000.5 RTM Standard Edition (64-bit)) we get following error:
DBC error. SQLSTATE: 42000 Native error: 1088 Message:
[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot find the object
"#POM_READ_EXPR_SCRATCH2" because it does not exist or you do not have
permissions. Approx SQL was "CREATE UNIQUE INDEX re_scratch_index ON
#POM_READ_EXPR_SCRATCH2 ( auid ) "
Error creating index re_scratch_index on table
#POM_READ_EXPR_SCRATCH2.
*** EIM_check_error: code 1088, dbmsg='[Microsoft][ODBC SQL Server Driver][SQL Server]Cannot find the object "#POM_READ_EXPR_SCRATCH2"
because it does not exist or you do not have permissions.'
We check the documentation, but didn't see any restriction of creating index on temp table. Can anyone explain why could this happens?
I think query you want is below:
CREATE TABLE #POM_read_expr_scratch2 (
auid VARCHAR(15) COLLATE Latin1_General_BIN INDEX re_scratch_index CLUSTERED
,aint_val INT
);
I'm writing a little script to extract the password hashes of SQL Logins on 2008 and 2012 instances. Part of my code looks like this...
SELECT CONVERT (VARCHAR(514), (SELECT CAST (LOGINPROPERTY('sa', 'PasswordHash') AS varbinary(256))), 2)
When I run this in a 2012 instance, it all works fine. But when run on a 2008 instance I get a blank result. I've checked that the SQL login is valid and has a password on the 2008. The online documentation tells me that all the functions are valid between both versions.
What is the difference between the versions?
Regards,
JC
Hash algorythms used:
SQL Server 2012 and above use SHA2-512 (512 bytes hash)
SQL Server 2000 to 2008 R2 use SHA1 (160 bytes hash)
You can also uses this query and DMV:
Select password_hash, * From sys.sql_logins Where name in ('sa')
It gives the same hash that this query:
Select CONVERT (varchar(512), (LOGINPROPERTY('sa', 'PasswordHash') ), 2)
Use this one if you want a varchar starting with 0x
Select CONVERT (varchar(514), (LOGINPROPERTY('sa', 'PasswordHash') ), 1)
SELECT
#Principal= IIF(optionfieldvalue='', NULL, CAST(optionfieldvalue as decimal(38, 18)))
FROM
#DATA
WHERE
TemplateFieldId = 47
This query was written in SQL Server 2012. Now I want to change that to SQL Server 2008 R2.
can any one help who to convert that code
Just get rid of the IIF which is new in SQL Server 2012:
SELECT
#Principal = CASE
WHEN optionfieldvalue = ''
THEN CAST(NULL AS DECIMAL(38,18))
ELSE CAST(optionfieldvalue AS DECIMAL(38, 18))
END
FROM
#DATA
WHERE
TemplateFieldId = 47
I am trying to convert from MS SQL Server 2008 Express to DB2 9.7.
I have installed IBM Migration Toolkit and successfully connected to my SQL Server database (hosted locally).
I tried to extract from database, keeping all default data mappings, but when I extract, I get the following (for all the tables) - Has anyone had a problem like this where all column types are null with Migration Toolkit?
At first I thought it might be because I am using the Express edition of SQL Server and maybe it couldn't see the column types under this application, but the fact that Name and Unit are null(50) and therefore it has understood that these columns have associated lengths makes me doubt this.
CREATE TABLE [Action] ([Id] null IDENTITY , [Name] null(50) NOT NULL , [UserId] null NOT NULL , [FreqId] null NOT NULL , [Quant] null NULL , [Unit] null(50) NULL , [Start] null NOT NULL , [End] null NOT NULL , [Created] null NOT NULL , [Modified] null NOT NULL , [Deleted] null NOT NULL )
I'm currently use DCW(data conversation workbench) toolkit, it's very useful to get all the data table of SQL Server 2008.
You may try DCW. Remind to you: after installing plugin to DB2, you must add driver of sql to DB2 (window->reference->data management -> connectivity> drive definitions)
I am creating a table that has a column called MonthName. When I defined this column the word "MonthName" showed up in blue like it was a reserved word. So I tried to look it up.
I cannot find it in Books Online or on Microsoft's site or even on our own SO.
I tried sp_help "monthname" and the reply was "The Object 'monthname' does not exists in database 'yourdb' or is invalid for this operation.
Here is the code
Create Table AtlasDataWarehouseReports.Calendar
(
CalendarId Integer NOT NULL,
DateValue Date NOT NULL,
DayOfTheWeek Integer NOT NULL,
NameOfDay VarChar (10) NOT NULL,
MonthNumber Integer NOT NULL,
MonthName VarChar (10) NOT NULL,
CalendarQuarter Integer NOT NULL,
NameOfCalendarQuarter VarChar (20) NOT NULL,
FinancialQuarter Integer NOT NULL,
NameOfFinancialQuarter VarChar (20) NOT NULL,
CalendarYear Integer NOT NULL,
FinancialYear Integer NOT NULL,
WeekOfYear Integer NOT NULL,
JulianDay Integer NOT NULL,
USAIsBankHoliday Bit NOT NULL,
USADayName VarChar (100) NULL,
)
SQL Server Version Info
Microsoft SQL Server Management Studio 10.0.2531.0
Microsoft Analysis Services Client Tools 10.0.1600.22
Microsoft Data Access Components (MDAC) 3.85.1132
Microsoft MSXML 2.6 3.0 4.0 5.0 6.0
Microsoft Internet Explorer 8.0.6001.18702
Microsoft .NET Framework 2.0.50727.3082
Operating System 5.1.2600
What, pray, is MonthName in SQL 2008?
as per msdn MonthName doesn't appear to be to be a reserved word.
Have you or anyone in your team written a function MonthName already?
As per this, SQL 2005 has introduced MonthName function, it seems.
EDIT: I think this could have been added to support SQL Reporting Services.
EDIT2: I dont have SQL management studio but try typing in any of the Reporting Services function names to see if they are highlighted in blue.
MONTHNAME is a reserved word in MySQL.
http://dev.mysql.com/doc/refman/5.1/en/date-and-time-functions.html#function_monthname
What IDE are you using that made the word show up as blue?