473,396 Members | 1,966 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,396 software developers and data experts.

error in sp code....

hi,
Please help me in following code of stored procedure….

My table and data: select * from nextGen_deven
--------------------------------------------------------------------------
Name1 enterdate convertedDate
Deven 2008-01-05 00:00:00.000 NULL
Deven1 2008-02-05 10:10:10.000 NULL
Deven2 2008-03-05 10:20:10.000 NULL
Deven3 2008-04-05 22:22:00.000 NULL
Deven4 2008-05-05 22:22:00.000 NULL
Deven5 2008-06-05 22:22:00.000 NULL
Deven6 2008-07-05 22:22:00.000 NULL
Deven7 2008-08-05 22:22:00.000 NULL
Deven8 2008-09-05 22:22:00.000 NULL
Deven9 2008-10-05 22:22:00.000 NULL
Deven10 2008-11-05 22:22:00.000 NULL
Deven11 2008-12-05 22:22:00.000 NULL

I have written stored procedure to add 2 hours or 1 hour in table data.

create PROCEDURE aim_sp_Convertdate_Deven AS
declare @DLSStart smalldatetime
, @DLSEnd smalldatetime
, @Date smalldatetime

/* please note: following two functions return me ‘2008-03-09 02:00:00’ and ‘2008-11-02 02:00:00’ values

(select dbo.fn_GetDaylightSavingsTimeStart(convert(varchar ,datepart(year,getdate())))) = ‘2008-03-09 02:00:00’

(select dbo.fn_GetDaylightSavingsTimeEnd(convert(varchar,d atepart(year,getdate())))) = ‘2008-11-02 02:00:00’

*/

set @DLSStart = (select dbo.fn_GetDaylightSavingsTimeStart(convert(varchar ,datepart(year,getdate()))))

set @DLSEnd = (select dbo.fn_GetDaylightSavingsTimeEnd(convert(varchar,d atepart(year,getdate()))))


DECLARE date_cursor CURSOR FOR
(select enterdate from nextGen_deven)
OPEN date_cursor
FETCH NEXT FROM date_cursor into @Date
WHILE @@FETCH_STATUS = 0
BEGIN
begin
update NextGen_Deven
set convertedDate = dateadd(hour, 1, enterDate)
where @Date between @DLSStart and @DLSEnd
end
begin
update NextGen_Deven
set convertedDate = dateadd(hour, 2, enterDate)
where @Date not between @DLSStart and @DLSEnd
end
FETCH NEXT FROM date_cursor into @Date END
CLOSE date_cursor
DEALLOCATE date_cursor



When I execute this procedure, it updates every row by adding 2 hours (not 1 hour in some of row)

Begin Tran abc
exec aim_sp_Convertdate_Deven
select * from nextGen_deven

my updated table data
--------------------------------------------------------------------------
Name1 enterdate convertedDate
Deven 2008-01-05 00:00:00.000 2008-01-05 02:00:00.000
Deven1 2008-02-05 10:10:10.000 2008-02-05 12:10:10.000
Deven2 2008-03-05 10:20:10.000 2008-03-05 12:20:10.000
Deven3 2008-04-05 22:22:00.000 2008-04-06 00:22:00.000 (should add 1 hour only, not 2 hours)
Deven4 2008-05-05 22:22:00.000 2008-05-06 00:22:00.000 (should add 1 hour only, not 2 hours)
Deven5 2008-06-05 22:22:00.000 2008-06-06 00:22:00.000 (should add 1 hour only, not 2 hours)
Deven6 2008-07-05 22:22:00.000 2008-07-06 00:22:00.000 (should add 1 hour only, not 2 hours)
Deven7 2008-08-05 22:22:00.000 2008-08-06 00:22:00.000 (should add 1 hour only, not 2 hours)
Deven8 2008-09-05 22:22:00.000 2008-09-06 00:22:00.000 (should add 1 hour only, not 2 hours)
Deven9 2008-10-05 22:22:00.000 2008-10-06 00:22:00.000 (should add 1 hour only, not 2 hours)
Deven10 2008-11-05 22:22:00.000 2008-11-06 00:22:00.000
Deven11 2008-12-05 22:22:00.000 2008-12-06 00:22:00.000


Thanks,
Deven Oza
Oct 19 '08 #1
4 1609
Delerna
1,134 Expert 1GB
I am looking at your while loop so I have removed the queries and added comments

Expand|Select|Wrap|Line Numbers
  1. WHILE @@FETCH_STATUS = 0
  2. BEGIN
  3. begin   --Huh...begin what, you have already begun the WHILE loop
  4.  
  5. end    --I suspect the while may be ending here
  6. begin --there should be an if or a while or something to begin
  7.  
  8. end  --Nothing to end
  9.  
  10.  
  11.  
  12. -- The fetch is outside any loop
  13. FETCH NEXT FROM date_cursor into @Date END
  14.  
Did this code actually run like this or have you edited it after pasting into your post?

I am also looking at the set for @DLSEnd and notice the eronious space d atepart

That should raise an error so I ask did you edit the code after pasting it and we are not seeing the full story? The while structure just dosn't look right to me.

Regards
Oct 19 '08 #2
Thank you for looking at my code.... that's true that I made some changes after posting it here.. Here I am posting my updated code... the problem is that the only ELSE part is working no matter what date I pass...
-------------------------------------------------------------------------
CREATE PROCEDURE aim_sp_Convertdate_Deven3 AS
DECLARE @DLSStart smalldatetime
, @DLSEnd smalldatetime
, @Date smalldatetime
SET @DLSStart = (select dbo.fn_GetDaylightSavingsTimeStart(convert(varchar ,datepart(year,getdate()))))
SET @DLSEnd = (select dbo.fn_GetDaylightSavingsTimeEnd(convert(varchar,d atepart(year,getdate()))))


DECLARE date_cursor CURSOR FOR
(select enterdate from nextGen_deven)
OPEN date_cursor
FETCH NEXT FROM date_cursor into @Date
WHILE @@FETCH_STATUS = 0
BEGIN
FETCH NEXT FROM date_cursor into @Date

if @Date between @DLSStart and @DLSEnd
Begin
update NextGen_Deven
set convertedDate = dateadd(hour, 2, enterDate)
END
Else
Begin
update NextGen_Deven
set convertedDate = dateadd(hour, 1, enterDate)
END
END
CLOSE date_cursor
DEALLOCATE date_cursor
-------------------------------------------------------------------------


I am looking at your while loop so I have removed the queries and added comments

Expand|Select|Wrap|Line Numbers
  1. WHILE @@FETCH_STATUS = 0
  2. BEGIN
  3. begin   --Huh...begin what, you have already begun the WHILE loop
  4.  
  5. end    --I suspect the while may be ending here
  6. begin --there should be an if or a while or something to begin
  7.  
  8. end  --Nothing to end
  9.  
  10.  
  11.  
  12. -- The fetch is outside any loop
  13. FETCH NEXT FROM date_cursor into @Date END
  14.  
Did this code actually run like this or have you edited it after pasting into your post?

I am also looking at the set for @DLSEnd and notice the eronious space d atepart

That should raise an error so I ask did you edit the code after pasting it and we are not seeing the full story? The while structure just dosn't look right to me.

Regards
Oct 20 '08 #3
Hey my code is working now by doing simply deleting cursor, now I am using simple two update statements and it is working fine, anyway thank you very much you looked at it.

ALTER PROCEDURE aim_sp_Convertdate_Deven2 AS
declare @DLSStart smalldatetime
, @DLSEnd smalldatetime
, @Date smalldatetime
--, @DLSActive tinyint
set @DLSStart = (select dbo.fn_GetDaylightSavingsTimeStart(convert(varchar ,datepart(year,getdate()))))
set @DLSEnd = (select dbo.fn_GetDaylightSavingsTimeEnd(convert(varchar,d atepart(year,getdate()))))

update nextGen_deven
set convertedDate = dateadd(hour, 2, enterDate)
where nextGen_deven.enterdate between @DLSStart and @DLSEnd

update nextGen_deven
set convertedDate = dateadd(hour, 1, enterDate)
where nextGen_deven.enterdate not between @DLSStart and @DLSEnd
Oct 20 '08 #4
Delerna
1,134 Expert 1GB
Yep, that was going to be my next question.
Steer clear of cursors if at all possible.

Good work getting it working. There's nothing like solving a problem !
Oct 20 '08 #5

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

Similar topics

5
by: Tony Wright | last post by:
Hi, I am having a problem installing an msi for a web site. The error message I am getting is: "The specified path 'http://mipdev05/features/Fas2' is unavailable. The Internet Information...
2
by: Gregory | last post by:
Hi, One of the disadvantages of using error handling with error codes instead of exception handling is that error codes retuned from a function can be forgotten to check thus leading to...
13
by: deko | last post by:
I use this convention frequently: Exit_Here: Exit Sub HandleErr: Select Case Err.Number Case 3163 Resume Next Case 3376 Resume Next
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
16
by: Steve Jorgensen | last post by:
I'm trying to figure out if there is a way to generate standard error handlers that "know" if the calling code has an error handler in effect (On Error Goto <label> or On Error Resume Next) before...
6
by: Squirrel | last post by:
I have a command button on a subform to delete a record. The only statement in the subroutine is: DoCmd.RunCommand acCmdDeleteRecord The subform's recordsource is "select * from tblVisit order...
7
by: p | last post by:
WE had a Crystal 8 WebApp using vs 2002 which we upgraded to VS2003. I also have Crystal 9 pro on my development machine. The web app runs fine on my dev machine but am having problems deploying....
4
by: Eugene Anthony | last post by:
One problem with the code bellow is after this code conn.qDupUser p1,rs I added: set rs = nothing to test the error handling capability.
2
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
hyperpau
by: hyperpau | last post by:
Before anything else, I am not a very technical expert when it comes to VBA coding. I learned most of what I know by the excellent Access/VBA forum from bytes.com (formerly thescripts.com). Ergo, I...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.