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.
Author |
Topic |
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-09-15 : 08:38:36
|
Dear All, I have the Following code, Declare @Date Datetime Declare @Year Int Declare @Month Int Declare @Day Int Select @Year = Year(@Cal_Effective_From_Date) - 1 Select @Month = Year(@Cal_Effective_From_Date) Select @Day = Year(@Cal_Effective_From_Date) Select @date = Convert(Datetime,CONVERT(Varchar(2),@Month)+'/'+CONVERT(Varchar(2),@Day)+'/'+CONVERT(varchar(4),@Year))But I received the following errorSyntax error converting datetime from character string.How can I Rectify this , Any one please help meThanks and regards krishnakumarThanksKK |
|
ditch
Master Smack Fu Yak Hacker
1466 Posts |
Posted - 2006-09-15 : 08:42:25
|
select dateadd(yy, -1, @Cal_Effective_From_Date)ohh and I am assuming that you are trying to subtract 1 from the year and not subtract 1 from the year and set the month to the year and set the day to the year as well.... Cos thats just impossible, how can you have a month or a day of 2006?Duane. |
 |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-09-15 : 08:50:20
|
thanks , It's Working |
 |
|
CSK
Constraint Violating Yak Guru
489 Posts |
Posted - 2006-09-15 : 09:15:24
|
That is In There I have put Year instead of day and month.I found the error |
 |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2006-09-15 : 19:09:59
|
And the day also.quote:
Select @Year = Year(@Cal_Effective_From_Date) - 1Select @Month = Year(@Cal_Effective_From_Date)Select @Day = Year(@Cal_Effective_From_Date)
Use the method Duane posted. It is easier. KH |
 |
|
|
|
|
|
|