ajaykumardev
Programmer
where condition is giving error
when we use between date column and two input dates .
when we are generating the date from concatinating of month,day,year in one select statement by using unpivot b'coz we have taken days as column D1........D31 like ..
and then in next layer we concat that column with month and year . when i use between then it gives error
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
The query is :
SELECT *
FROM (
SELECT DISTINCT YEAR,MONTH,CONVERT(DATE,CONVERT(VARCHAR(10),C.YEAR) + '-' + convert(varchar(20),C.MONTH) +'-'+ REPLACE(daay,'d','')) AS AttDate
FROM (SELECT D.*
FROM dbo.DAILYATND AS D
INNER JOIN dbo.EMPLOYEE AS E ON ( D.EMPCODE = E.EMPCODE )
) AS Z UNPIVOT ( value FOR daay IN ( [D1], [D10],
[D11], [D12],
[D13], [D14],
[D15], [D16],
[D17], [D18],
[D19], [D2],
[D20], [D21],
[D22], [D23],
[D24], [D25],
[D26], [D27],
[D28], [D29],
[D3], [D30],
[D31], [D4],
[D5], [D6], [D7],
[D8], [D9] ) ) AS C
) AS y
WHERE CONVERT(date,AttDate) BETWEEN '2013-02-02' AND '2013-02-21'
when we use between date column and two input dates .
when we are generating the date from concatinating of month,day,year in one select statement by using unpivot b'coz we have taken days as column D1........D31 like ..
and then in next layer we concat that column with month and year . when i use between then it gives error
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
The query is :
SELECT *
FROM (
SELECT DISTINCT YEAR,MONTH,CONVERT(DATE,CONVERT(VARCHAR(10),C.YEAR) + '-' + convert(varchar(20),C.MONTH) +'-'+ REPLACE(daay,'d','')) AS AttDate
FROM (SELECT D.*
FROM dbo.DAILYATND AS D
INNER JOIN dbo.EMPLOYEE AS E ON ( D.EMPCODE = E.EMPCODE )
) AS Z UNPIVOT ( value FOR daay IN ( [D1], [D10],
[D11], [D12],
[D13], [D14],
[D15], [D16],
[D17], [D18],
[D19], [D2],
[D20], [D21],
[D22], [D23],
[D24], [D25],
[D26], [D27],
[D28], [D29],
[D3], [D30],
[D31], [D4],
[D5], [D6], [D7],
[D8], [D9] ) ) AS C
) AS y
WHERE CONVERT(date,AttDate) BETWEEN '2013-02-02' AND '2013-02-21'