How to check if a date is a valid date in Sql Server 2005
2008-04-02 14:32
681 查看
At times, in our stored procedures or sql queries, we need to check if the date specified in the variables is a valid date.
Use the ISDATE() function.
The
ISDATE() function determines whether the variable or the expression
contains a valid date. It returns 1(true) if the input expression is a
valid date; otherwise, it returns 0 (false).
For eg:
DECLARE @dt varchar(10)
SET @dt = '02/21/08'
SELECT ISDATE(@dt)
-- Returns 1
DECLARE @dt varchar(10)
SET @dt = '13/21/08'
SELECT ISDATE(@dt)
-- Returns 0 as 13 is not a valid month
Use the ISDATE() function.
The
ISDATE() function determines whether the variable or the expression
contains a valid date. It returns 1(true) if the input expression is a
valid date; otherwise, it returns 0 (false).
For eg:
DECLARE @dt varchar(10)
SET @dt = '02/21/08'
SELECT ISDATE(@dt)
-- Returns 1
DECLARE @dt varchar(10)
SET @dt = '13/21/08'
SELECT ISDATE(@dt)
-- Returns 0 as 13 is not a valid month
相关文章推荐
- How to format datetime & date in Sql Server 2005
- How to check if the silverlight application is in design mode?
- How to enable sa user account in SQL Server 2005
- How to recreate the msdb database in SQL Server 2005
- How to check Fragmentation on SQL Server 2005
- HOW TO: Change the Owner of a User-Defined Data Type That Is in Use in SQL Server 2000
- How to build an OLE DB application for SQL Server CE in Visual Studio 2005
- How to Alter a Replicated Article in SQL Server 2005
- How to check if a Number is Positive or Negative in Java - Interview Question
- Android How to Check if the App is in Background
- How to check fragmentation on SQL Server 2005
- How to Implement an Automatic Sliding Window in a Partitioned Table on SQL Server 2005
- How to check Fragmentation on SQL Server 2005
- How to monitor blocking in SQL Server 2005 and in SQL Server 2000 [ZT-MS]
- how to debug store procedure in sql server 2005
- How to check number of Active connections in SQL server?
- Disaster Recovery: What to do when the SA account password is lost in SQL Server 2005
- How to Check Whether Oracle Binary/Instance is RAC Enabled and Relink Oracle Binary in RAC (文档 ID 28
- HOW TO CHECK FOR ACTIVE TRACE FLAGS ON MICROSOFT SQL SERVER
- how to use danymic sql in SQL Server 2000