473,425 Members | 1,581 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,425 software developers and data experts.

how to compare two dates in stored procedure?

In this procedure im comparing two dates. Its the stored procedure could be executed. Im face an problem when executing this stored procedure.

Error:exec sp_valid
@coupon_no = 101



Msg 242, Level 16, State 3, Procedure sp_valid, Line 13
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
Msg 241, Level 16, State 1, Procedure sp_valid, Line 17
Conversion failed when converting datetime from character string.




<code>set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go

ALTER procedure [dbo].[sp_valid]
(
@coupon_no int
)
as
begin
if not exists(select couponno from coupons where couponno = @coupon_no)
select 'the coupon no is incorrect'
declare @issue_date DATETIME
select @issue_date = validupto from coupons where couponno = @coupon_no
declare @valid_upto Datetime
select @valid_upto = validupto from coupons where couponno = @coupon_no
select convert (int, convert (datetime,'99995862 23:59:59:997'))
if ((@issue_date) > (@valid_upto))
select 'the coupon is expire'
else
select 'the coupon will expires on ' + @valid_upto
end </code>



Table code:

<code>
USE [vvit]
GO
/****** Object: Table [dbo].[coupons] Script Date: 07/17/2010 11:15:57 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE TABLE [dbo].[coupons](
[couponno] [int] NULL,
[issuedate] [datetime] NULL CONSTRAINT [DF_coupons_issuedate] DEFAULT (getdate()),
[validupto] AS ([issuedate]+(30))
) ON [PRIMARY]

</code>
Jul 17 '10 #1
1 5875
Delerna
1,134 Expert 1GB
can you explain what you are trying to do with this line ?

Expand|Select|Wrap|Line Numbers
  1. select convert (int, convert (datetime,'99995862 23:59:59:997'))
  2.  
The error is resulting from trying to convert 99995862 to a date
What is that?
Jul 19 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Milo Woodward | last post by:
I have some columns of data in SQL server that are of NVARCHAR(420) format but they are dates. The dates are in DD/MM/YY format. I want to be able to convert them to our accounting system format...
3
by: Jim Armstrong | last post by:
Hello all, I have a database with trade information. I have written a stored procedure (code at end of post) which pulls trades from a range of dates. There is a field called "Match ID" which is...
3
by: Bilbo | last post by:
I have a a headscratcher here: I have a form that when submitted should do 2 things when a user enters data and then clicks the Add button. Here goes: 1. Call a stored procedure called...
2
by: satish | last post by:
hi, i am a learner of ms -sql server 2000, i had a doubt in stored procedures suppose i have a data base having 20 tables, all the tables have a column named--DATE can we write a store...
3
by: rsbutterfly16 | last post by:
hi all, I have a front end access database (mdb) with a sql server backend for my tables. I have an form in which I have created a store procedure in sql server, and i have a form created and also...
1
by: mickyang | last post by:
My MS-SQL 2000 Database have 50 more Stored Procedure . How to FAST and EASY ENCRYPTION ALL Stored Procedure in my MS-SQL Database?
1
by: brianlanning | last post by:
We have a stored procedure that we've tried with two slightly different designs. It needs to take a 30 day date range and return a result set. Design 1 takes one date as a parameter. The other...
2
by: nguyenmiket | last post by:
I have created a crystal report in XI that uses a stored procedure with two date parameters. When i run it in Crystal reports it prompts me for the dates. When i put it in a view in a .aspx page,...
0
by: stavo23 | last post by:
I am using SQL Server 2000, and I want to write a stored procedure that returns certain values either between 2 dates (start and end) or the user enters a particular string. Its grafts a bit , but...
3
by: Constantine AI | last post by:
Hi we have created a stored procedure to check the dates entered into a lease table does not overlap dates already stored for a lease. However when inserting overlapping lease dates, it allows us to...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.