I have a column called date with data that looks like this:2012-01-012011-01-01This is in DATE format not varchar.I want to create a computed column from these fields to look like this (I want this to be VARCHAR):21201012110101I have the concatenate statement that will give me the numbers:SELECT substring (cast( Date as varchar(10)), 1, 1) + substring(cast( Date as varchar(10)), 3, 2) + substring(cast( Date as varchar(10)), 6, 2) +substring(cast( Date as varchar(10)), 9, 2)FROM TestTable
This query gives me this:21201012110101(which is the correct format)Now I try to create the computed column to look like this:ALTER TABLE TestTable ADD testcolumn as substring (cast( StartDate as varchar(10)), 1, 1) + substring(cast( StartDate as varchar(10)), 3, 2) + substring(cast( StartDate as varchar(10)), 6, 2) +substring(cast( StartDate as varchar(10)), 9, 2)
Instead of giving me:21201012110101this column gives me:Jn 1 01Jn 1 01I am beyond puzzled