sql - Conversion failed when converting date and/or time from character string month(),year() -
i have these data:
col1 col2 col3 2014-12-31 q 2014-12-10 q create table persons ( col1 varchar(50), col2 varchar(50), col3 varchar(20) ); insert persons(col1, col2,col3) values ('2014-12-20', 'q',''); insert persons(col1, col2,col3) values ('2014-12-10', 'q','');
i run query:
select convert(date, col1,104) col1, col2, case when col2 = 'q' convert(nvarchar(10),year(col1)+'q0') end col3 persons
i error:
conversion failed when converting date and/or time character string
declare @p table ( col1 varchar(50), col2 varchar(50), col3 varchar(20) ) insert @p(col1, col2,col3) values ('2014-12-20', 'q',''); insert @p(col1, col2,col3) values ('2014-12-10', 'q',''); select convert(varchar(10), col1,104) col1, col2, case when col2 = 'q' right(convert(nvarchar(10),year(col1),106),5) + 'q0' end col3 @p
output:
Comments
Post a Comment