Is MonthName a reserved word in SQL 2008 - sql-server

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?

Related

Does Microsoft SQL Server provides bitemporal historization?

I want to use bitemporal historization in Microsoft SQL Server as in know it from e.g. DB2 (https://www.ibm.com/docs/en/db2-for-zos/12?topic=tables-creating-bitemporal).
There we can create a table via
CREATE TABLE policy_info
(policy_id CHAR(4) NOT NULL,
coverage INT NOT NULL,
bus_start DATE NOT NULL,
bus_end DATE NOT NULL,
sys_start TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW BEGIN,
sys_end TIMESTAMP(12) NOT NULL GENERATED ALWAYS AS ROW END,
create_id TIMESTAMP(12) GENERATED ALWAYS AS TRANSACTION START ID,
PERIOD BUSINESS_TIME(bus_start, bus_end),
PERIOD SYSTEM_TIME(sys_start, sys_end));
where
SYSTEM_TIME (works in MSQL_Server) refers to technical information in database changes and logs everything in a history-table and
BUSINESS_TIME (does it exist in MSQL server?) refers to the business-reated validity of data (e.g. the lastname of Employee with Employee_ID = 4711 was "Schmidt" from 3.6.21 until 5.7.21 and "Müller" from 6.7.21 until 23.1.22).
Does Microsoft SQL-Server provide a feature analogue to the BUSINESS_TIME in DB2?
Answer from comment: There is no bitemporal historization for SQL-Server.

Error “The timezone provided to builtin function todatetimeoffset is invalid.”

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?

Sql Server ODBC Date Field - Optional feature not implemented

I have a SQL Server table which has fields of type Date in it. I am trying to update or insert a record into the table via Micosoft Access using ODBC. I get the error:
[ODBC SQL Server Driver]Optional feature not implemented
when I try and update or insert a record.
I have to use Date fields not DateTime fields in my table because I am using very old dates going back 2000 years.
Is there any way round this problem, which I assume is caused by the Date fields?
This is what the table looks like
CREATE TABLE [dbo].[Person](
[PersonId] [int] IDENTITY(1,1) NOT NULL,
[DOB] [date] NOT NULL,
[DOD] [date] NULL DEFAULT (NULL),
[Name] [nvarchar](100) NOT NULL)
You best bet is to dump the use of the "legacy" sql driver, and user the newer native 10 or 11 driver. The older driver will view date fields as text, but using the newer native 10/11 driver will see the column as a date column. This will require you to re-link your tables.
If you can't change your SQL Server version, an easier solution is to pass the date as an adVarChar, and then do a CAST(#param AS DATE) in your SQL stored procedure.
I've experienced the same problem today.
I use MsAccess 2010 for developlemt, and have MsSql2012 at back-end.
There was no problem on my computer,
but other clients that use the accde runtime version has experienced this trouble.
After several trials;
Issue resolved when replacing DATE type with SMALLDATETIME. please try this..?
Indeed I only needed the date part, not the time, but ok anyway!
[DOB] [date] NOT NULL,
[DOD] [date] NULL DEFAULT (NULL),
Hope this helps to you as well

DateTime2 as input parameter datatype in Table-Valued Function

I have the following table-valued function:
[Microsoft.SqlServer.Server.SqlFunction(SystemDataAccess = SystemDataAccessKind.Read,
FillRowMethodName ="XXX", TableDefinition = "time DateTime2"]
public static IEnumerable ValueAtTime(string somestring, DateTime inputTime)
{
...
}
As you can see in the table definition I can define DateTime2 as a column datatype. I would also like to do the same for the input parameter "InputTime", but since this parameter is a .NET type, I am unable to. Is there a way to do that in order to get DateTime2 in the SQL definition as an input parameter?
Actually, the .NET DateTime type is the correct one to use to pass back and forth DATETIME2 values. And, since it is a .NET type and not one of the SqlTypes types (which all have a .IsNull property), if you need to allow for NULLs, then use DateTime?.
To help clarify, it sounds like the assumption is that SQL Server's DATETIME datatype has an equivalent DateTime type in .NET, so then SQL Server's DATETIME2 datatype should likewise have a .NET equivalent, especially if DATETIME2 has greater range and precision. Don't be confused by the similarity in name of DATETIME and DateTime between the two environments. SQL Server's DATETIME has less range and precise than .NET's DateTime, whereas DATETIME2 has the same range and precision:
Type Environment Min Date Max Date Precision
---- ----------- ---------- ---------- ---------
DATETIME SQL Server 1753-01-01 9999-12-31 .000, .003, and .007 seconds
DATETIME2 SQL Server 0001-01-01 9999-12-31 .0000001 seconds
DateTime .NET 0001-01-01 9999-12-31 .0000001 seconds
For more info, please see:
DATETIME
DATETIME2
DateTime
Stairway to SQLCLR Level 5: Development (Using .NET within SQL Server) (an article I wrote for a series on SQLCLR; free registration is required)
Also:
I would recommend against naming the output field "time", though, since it is a SQL Server reserved word in addition to being a little misleading (since there is also a TIME datatype in SQL Server).
You should be using SqlString instead of string for the other input parameter.
Why not? Below is an excerpt from working code. Works just fine with SQL Server 2008.
[SqlFunction(
FillRowMethodName = "FillRow",
DataAccess = DataAccessKind.None,
IsDeterministic = true,
IsPrecise = true)]
public static IEnumerable ParsePacket(
byte[] packet)
{ ... }
public static void FillRow(
object rowdata,
out DateTime? time,
out short peer,
out int addr,
out byte quality,
out bool? state,
out float? value)
{ ... }
and
CREATE FUNCTION [split_packet] (#data [varbinary](300))
RETURNS TABLE (
[time] [datetimems] NULL,
[peer] [smallint] NULL,
[n] [int] NULL,
[quality] [tinyint] NULL,
[state] [bit] NULL,
[value] [real] NULL
)
AS
EXTERNAL NAME [Iec104Parser].[UDF].[ParsePacket]
Not so fine with 2005... :-(
While this is output, I don't see why there could be problems with input (microsoft does not seem to differentiate on that).

SQL Server to DB2 Conversion: Migration Toolkit Issues

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)

Resources