Error message

  • Thread starter Thread starter bbawa1
  • Start date Start date
B

bbawa1

Again thanks a lot but When I execute only this portion it gives me
error

Syntax error converting the varchar value '2d 0h 0m' to a column of
data
type int.

My stored procedure is the following.

Followed is the SQL Script and you can use this code in your SQL
Function to
get the difference and make function with StartDate and EndDate
parameters
and return the @Diff

DECLARE @Day INT
DECLARE @Hour INT
DECLARE @Minute INT
DECLARE @Start_Date DateTime
DECLARE @End_Date DateTime
SET @Start_Date = '6/13/2007 12:38 AM'
SET @End_Date = '6/14/2007 11:59 PM'
SET @Day = DATEDIFF( day, @Start_Date, @End_Date)
SET @Hour = DATEDIFF(hour , @Start_Date, @End_Date)
SET @Minute = DATEDIFF(minute , @Start_Date, @End_Date)
SET @Minute = @Minute-(@HOUR* 60)
SET @Hour = @Hour-(24* @Day)
SET @Diff = CONVERT( Varchar, @Day) +'d ' + CONVERT(Varchar , @Hour) +
'h '
+ CONVERT(Varchar , @Minute) +'m'
PRINT
'Difference : ' + @Diff
 
Again thanks a lot but When I execute only this portion it gives me
error

Syntax error converting the varchar value '2d 0h 0m' to a column of
data
type int.

My stored procedure is the following.

Followed is the SQL Script and you can use this code in your SQL
Function to
get the difference and make function with StartDate and EndDate
parameters
and return the @Diff

DECLARE @Day INT
DECLARE @Hour INT
DECLARE @Minute INT
DECLARE @Start_Date DateTime
DECLARE @End_Date DateTime
SET @Start_Date = '6/13/2007 12:38 AM'
SET @End_Date = '6/14/2007 11:59 PM'
SET @Day = DATEDIFF( day, @Start_Date, @End_Date)
SET @Hour = DATEDIFF(hour , @Start_Date, @End_Date)
SET @Minute = DATEDIFF(minute , @Start_Date, @End_Date)
SET @Minute = @Minute-(@HOUR* 60)
SET @Hour = @Hour-(24* @Day)
SET @Diff = CONVERT( Varchar, @Day) +'d ' + CONVERT(Varchar , @Hour) +
'h '
+ CONVERT(Varchar , @Minute) +'m'
PRINT
'Difference : ' + @Diff

@Diff requires a value of type int

SET @Diff = CONVERT( Varchar, @Day) +'d ' + CONVERT(Varchar , @Hour) +
'h ' + CONVERT(Varchar , @Minute) +'m'
 
Back
Top