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 |
|
jfm
Posting Yak Master
145 Posts |
Posted - 2012-05-24 : 05:05:21
|
| HI, I have an error in this query. Any idea why? USE my_databaseALTER TABLE my_tableADD New_column AS ((MONTH(REPARATION_DATE) AS varchar(2)) + '-' + YEAR(REPARATION_DATE) AS varchar(4)))Thanks |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2012-05-24 : 05:08:54
|
you need to use CONVERT() or CAST() to convert it to varcharADD New_column AS (CAST (MONTH(REPARATION_DATE) AS varchar(2)) + '-' + CAST (YEAR(REPARATION_DATE) AS varchar(4))) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
jfm
Posting Yak Master
145 Posts |
Posted - 2012-05-24 : 05:14:08
|
Perfect!!!!Thanks so muchquote: Originally posted by khtan you need to use CONVERT() or CAST() to convert it to varcharADD New_column AS (CAST (MONTH(REPARATION_DATE) AS varchar(2)) + '-' + CAST (YEAR(REPARATION_DATE) AS varchar(4))) KH[spoiler]Time is always against us[/spoiler]
|
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-05-24 : 15:42:39
|
| why should you add this column to table itself? I would have stored only base column (REPARATION_DATE) in table and would have done this only at front end to display the data in required format using formatting functions.------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2012-05-30 : 05:08:47
|
| or use a computed column as part of SELECT statement to have thatMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|