在Hijri约会工作......面临错误...... plzzz帮助 [英] working on Hijri dates... facing error... plzzz help

查看:61
本文介绍了在Hijri约会工作......面临错误...... plzzz帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个G-date n Hijri-date的表,

其中我在d表中将这些col作为varchar(10)数据类型。



我的存储过程:

 USE [RAS] 
GO
/ ******对象:StoredProcedure [dbo]。 [Sp_InsertEmployee]脚本日期:02/12/2014 17:26:49 ****** /
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo]。[Sp_InsertEmployee]

@Branchcode int
,@ Joinningdate date
,@ Empname nvarchar(50)
,@ IqamaExp varchar( 10)
,@ IqamaExpArabic varchar(10)


- Sp_InsertEmployee 1,null,null,1,1,1,1,null,'02 / 02 / 2014','02/02/1435',null,null,null,null,null,null,null,null,null,null,null,null,null,null,1

AS BEGIN
INSERT INTO [RAS]。[dbo]。[tbl_Employee]
([Branchcode]
,[Joinningdate]
,[Position]
,[IqamaExp]
,[IqamaExpArabic]

VALUES

@Branchcode
,@ Joinningdate
,@ Empname
,convert(varchar(10),@ IqamaExp,101)
,转换(varchar(10),@ IqamaExpArabic,101)



END

打印CONVERT(datetime,@ IqamaExp ,101)
打印CONVERT(datetime,@ IqamaExpArabic,101)







结果:



(1行受影响)
2014年2月2日12:00 AM
消息242,等级16,状态3,过程Sp_InsertEmployee,第91行
将varchar数据类型转换为日期时间数据类型导致超出范围的值。





当我将它插入d storedprocedure时,它显示我这个错误..



但是,如果我从asp.net调用它页面...显示转换日期/时间错误...





plz ...帮帮我

解决方案

这是另一种可能的解决方案您可以将日期存储在DATETIME数据类型( Gregorian 日历)中,并在 Gregorian Hijri 日期之间使用转换函数。



示例:



Hijri 约会 Gregorian 日期:

  DECLARE   @HijriDate   VARCHAR  10 )= '  02/02/1435'; 
SELECT CONVERT DATETIME @ HijriDate 131 );



公历日期:2013-12-05 00:00:00.000



Gregorian 约会 Hijri date:

  DECLARE   @GregorianDate   DATETIME  = '  02/13/2014' ; 
SELECT CONVERT VARCHAR 25 ), @GregorianDate 131 );



Hijri日期:13/04/1435 12:00:00:000AM



你可以在这里找到更多信息:

1. SQL Server Hijri(Hijra)日期 [ ^ ]

2. SQL SERVER - 如何使用格式化将格里高利日期转换为Hijri日期 [ ^ ]





----------------- -------------------------------------------------- --------------------

这是重要的!!!



我做了一些研究并发现了这个:

不幸的是,这个解决方案仅适用于科威特Hijri日历



我将说明问题。根据Umm al-Qura日历 30/02/1434 是有效日期(匹配 01/12/2013 )。但是如果你试试这个:

  DECLARE   @ HijriDate   VARCHAR  10 )= '  30/02/1434'; 
SELECT CONVERT DATETIME @ HijriDate 131 );



你将得到这个:

将varchar数据类型转换为日期时间数据类型会导致超出范围的值。



这是因为根据科威特算法 30/02/1434 是有效日期。 Hijri是一个有多种变体的日历系统.SQL Server使用科威特算法。 - Microsoft 。相比之下, Google 日历目前支持Hijri日历的三种主要变体。



其他可能的解决方案:

1.查看解决方案1 ​​

2.将日期存储为 SQL Server (Gregorian)中的DATETIME在ASP.NET(Hijra,Umm al-Qura)中实现日期转换。这可能很有用: Um Al Qura(Hijri)日历 [ ^ ]


请参阅有关问题评论的讨论。看起来标准的DATE和DATETIME数据类型是为(常规的)西方(格里高利)日历的(有限!)支持而设计的,并且不适合Hijri,由于它的历史根源,我们实际上更复杂:http://en.wikipedia.org/wiki/Hijri [ ^ ]。



我最初的想法是:你需要开发自己的数据用来表示Hijri日期的类型。它可能在日期表中使用多个整数列。重要的是不要试图将Hijri表示为字符串;始终使用一些数字类型来表示时间点的组件。按照您可以从上面引用的页面或其他可靠来源构建的日历定义。此外,您还可以了解其他人如何解决此问题: http://bit.ly/1bpEPQW [ ^ ]。



-SA

i have a table with G-date n Hijri-date,
where i have these col as varchar(10) datatype in d table.

my stored procedure:

USE [RAS]
GO
/****** Object:  StoredProcedure [dbo].[Sp_InsertEmployee]    Script Date: 02/12/2014 17:26:49 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROC [dbo].[Sp_InsertEmployee]
(			
			@Branchcode int
           ,@Joinningdate date
           ,@Empname nvarchar(50)      
           ,@IqamaExp varchar(10)
           ,@IqamaExpArabic varchar(10)
)

-- Sp_InsertEmployee 1,null,null,1,1,1,1,null,'02/02/2014','02/02/1435',null,null,null,null,null,null,null,null,null,null,null,null,null,null,1

AS BEGIN
INSERT INTO [RAS].[dbo].[tbl_Employee]
           ([Branchcode]
           ,[Joinningdate]
           ,[Position]
           ,[IqamaExp]
           ,[IqamaExpArabic]
          )
     VALUES
     (			
			@Branchcode 
           ,@Joinningdate 
           ,@Empname 
          ,convert(varchar(10),@IqamaExp, 101)
           ,convert(varchar(10),@IqamaExpArabic, 101)
           
     )
           
END

print CONVERT(datetime,@IqamaExp, 101)
print CONVERT(datetime,@IqamaExpArabic, 101)




result:

(1 row(s) affected)
Feb  2 2014 12:00AM
Msg 242, Level 16, State 3, Procedure Sp_InsertEmployee, Line 91
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.



when i'm insert it in d storedprocedure, its showing me this error..

but, if i call this from asp.net page... its showing converting date / time error...


plz ... help me

解决方案

Here is another possible solution. You can store your dates in DATETIME data type (Gregorian calendar) and use convert functions between Gregorian and Hijri dates.

EXAMPLES:

Hijri date to Gregorian date:

DECLARE @HijriDate VARCHAR(10) = '02/02/1435';
SELECT CONVERT(DATETIME, @HijriDate, 131);


Gregorian date: 2013-12-05 00:00:00.000

Gregorian date to Hijri date:

DECLARE @GregorianDate DATETIME = '02/13/2014';
SELECT CONVERT(VARCHAR(25), @GregorianDate, 131);


Hijri date: 13/04/1435 12:00:00:000AM

You can find more information here:
1. SQL Server Hijri (Hijra) Dates[^]
2. SQL SERVER – How to convert Gregorian dates to Hijri date with Formatting[^]


---------------------------------------------------------------------------------------
THIS IS IMPORTANT!!!

I did some research and found out this:
Unfortunately, this solution works correctly only for the Kuwaiti Hijri calendar.

I'm going to illustrate the problem. According to Umm al-Qura calendar 30/02/1434 is a valid date (matches 01/12/2013). But if you try this:

DECLARE @HijriDate VARCHAR(10) = '30/02/1434';
SELECT CONVERT(DATETIME, @HijriDate, 131);


you are going to get this:
The conversion of a varchar data type to a datetime data type resulted in an out-of-range value.

This happened because according to the Kuwaiti algorithm 30/02/1434 is not a valid date. "Hijri is a calendar system with several variations. SQL Server uses the Kuwaiti algorithm." - Microsoft. In comparison, Google Calendar currently supports three major variations of Hijri calendar.

Other possible solutions:
1. Look at the solution 1.
2. Store your dates as DATETIME in SQL Server (Gregorian) and implement date conversion in ASP.NET (Hijra, Umm al-Qura). This might be useful: Um Al Qura (Hijri) Calendar[^]


Please see the discussions on the comment to the question. It looks like standard DATE and DATETIME data type are designed for (limited!) support of "regular" Western (Gregorian) calendar and are not suitable for Hijri, which us actually more complex, due to its historical roots: http://en.wikipedia.org/wiki/Hijri[^].

My initial idea was: you would need to develop your own data type to represent Hijri dates. It can possibly use more than one integer column in the date table. It is important not to try to represent the Hijri as a string; always use some numeric types to represent the components of the point in time. Follow the definition of the calendar you can build from the page referenced above or other reliable sources. Also, you can take a look at how other people solved this problem: http://bit.ly/1bpEPQW[^].

—SA


这篇关于在Hijri约会工作......面临错误...... plzzz帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆