Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 sql stored procedure

Author  Topic 

Rajagopalan
Starting Member

1 Post

Posted - 2014-04-12 : 04:29:07
HI

I created one stored procedure to update the date difference in the table . in this table i have dt1,dt2,dt3... column and diff1,diff2...
i wanted to find the difference between dt2 and dt1, and dt4 and dt3 and put it in separate column.
when i compiled the stored procedure, it did not show any error.
but when i execute, it shows the error:

Conversion failed when converting datetime from character string.

I dont know where i made a mistake.

Can any one help on this.

thanks


set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
go


ALTER procedure [dbo].[autopost1]
as
begin
declare inner int
declare @fmm varchar(4),@too varchar(4)

declare @hours as int
declare @minutes as int
declare @seconds as int
declare @time_interval as nvarchar(10)

set @instart = 1

while @instart <= @inner
begin
set @fmm = 'dt'+cast(@instart-1 as varchar)
set @too = 'dt'+cast(@instart as varchar)

set @hours = DATEDIFF(ss, @fmm, @too) / 3600
set @minutes = (DATEDIFF(ss, @fmm, @too) - @hours*3600)/60
set @seconds = DATEDIFF(ss, @fmm, @too) - @hours*3600 - @minutes * 60
set @time_interval = (cast(@hours as nvarchar) +':'+ cast(@minutes as nvarchar)+':'+ cast(@seconds as nvarchar))

set @instart = @instart + 1
end


nandiniforum
Starting Member

1 Post

Posted - 2014-04-12 : 04:33:23
hii

http://logicshore.com/
Go to Top of Page
   

- Advertisement -