hi,
i am facing an issue in converting one of the date format to other.
The current date format is 1/1/2010
Required format is Jan-10
I have used the following code to convert it. Its working fine in source table not in the target table. In both tables, i have defined data type in both the tables as varchar only.
Conversion:
When i execute above query separately for this table, its working fine(as shown).
But when i implement the same to stored procedure its not working and its throwing an error message.
Error i am getting
Msg 8117, Level 16, State 1, Procedure NAT_Changes_SFA, Line 10
Operand data type varchar is invalid for subtract operator.
Thanks, for your help.
i am facing an issue in converting one of the date format to other.
The current date format is 1/1/2010
Required format is Jan-10
I have used the following code to convert it. Its working fine in source table not in the target table. In both tables, i have defined data type in both the tables as varchar only.
Conversion:
Code:
CONVERT(CHAR(4), convert(datetime,Period), 100) +'-'+ substring(CONVERT(CHAR(4),
convert(datetime,Period), 120),3,4)
When i execute above query separately for this table, its working fine(as shown).
Code:
select CONVERT(CHAR(4), convert(datetime,Period), 100) +'-'+ substring(CONVERT(CHAR(4),
convert(datetime,Period), 120),3,4)
from REAS_HPI_STATE_Final
order by Period desc
But when i implement the same to stored procedure its not working and its throwing an error message.
Code:
USE [REAS]
GO
/****** Object: StoredProcedure [dbo].[NAT_Changes_SFA] Script Date: 01/08/2011 07:00:43 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER Procedure [dbo].[NAT_Changes_SFA]
As Begin
declare @SQL varchar(max)
Begin
If object_id('NAT_AllChanges_SFA_Temp','U') is not null drop table NAT_AllChanges_SFA_Temp
Set @SQL= '(Insert into NAT_AllChanges_SFA_Temp as
SELECT (CONVERT(CHAR(4), convert(datetime,Period), 100) +'-'+ substring(CONVERT(CHAR(4),
convert(datetime,Period), 120),3,4),
HPI_1M_Change * 100 , HPI_3M_Change * 100 , HPI_6M_Change * 100 , HPI_12M_Change * 100 , Home_Price_Index
FROM dbo.REAS_HPI_STATE_Final
WHERE Tier_Code = 7 AND STATE_Code = 00
ORDER BY period DESC)'
execute (@SQL)
End;
END;
Error i am getting
Msg 8117, Level 16, State 1, Procedure NAT_Changes_SFA, Line 10
Operand data type varchar is invalid for subtract operator.
Thanks, for your help.