I have the following SQL query:
SELECT D.name, X.displayName, x.diff, X.tacticalParameter_id
FROM (
select displayName, tacticalParameter_id, b.value,datediff(DAY,convert(date,b.value,101),convert(date,getdate(),101)) as diff from EDA_TENANT1.EDA_T_P_A A, eda_tenant1.EDA_T_P_A_V b
where b.attribute_id = A.ID
and displayName like 'Fecha %'
and value <> '') X,
EDA_TENANT1.EDA_T_P C, EDA_TENANT1.EDA_TACT_P_G D
WHERE X.tacticalParameter_id = C.id
AND C.tacticalParameterGroup_id = D.id
and D.NAME in ('TPG Codigo postal - SPG Codigo postal',
'TPG Cuenta bancaria - SPG Cuenta bancaria',
'TPG Direccion - SPG Direccion',
'TPG Doc identidad - SPG Doc identidad',
'TPG Email - SPG Email',
'TPG Nombre - SPG Nombre',
'TPG Nombre empresa - SPG Nombre empresa',
'TPG Telf empresa - SPG Telf empresa',
'TPG Telf empresa movil - SPG Telf empresa movil',
'TPG Telf fijo - SPG Telf fijo',
'TPG Telf movil - SPG Telf movil',
'TPG Codigo agente - SPG Codigo agente',
'TPG Fiscal num - SPG Fiscal num')
which produces the following results:
name displayName diff tacticalParameter_id
TPG Email - SPG Email Fecha purga email -245 48e221cc-6628-4e6b-880f-d68d0f074d72
TPG Email - SPG Email Fecha purga email -294 78455c15-4f60-433e-a687-121a4098baeb
TPG Nombre - SPG Nombre Fecha purga nombre y apellidos -287 52227b6b-7497-4533-93c1-72c736175ef8
TPG Telf movil - SPG Telf movil Fecha purga telefono 2 -308 e8c465f9-cf74-4fe8-89ee-41d618055ab7
TPG Fiscal num - SPG Fiscal num Fecha purga doc identidad -189 ed41d6a1-1c77-48d7-bfb7-eafac767084b
TPG Telf movil - SPG Telf movil Fecha purga telefono 2 -266 e7d500f2-1971-41f2-a24c-00edc7b2c7f0
TPG Email - SPG Email Fecha purga email -161 81593640-f080-4d11-afae-c822c4a51f05
TPG Email - SPG Email Fecha purga email -77 fcb880f8-cb3d-4180-9c7c-01d7cdb04022
When I try to put all the results into new table I get the following error:
SELECT D.name, X.displayName, x.diff, X.tacticalParameter_id
into kk_aux -- only change
FROM (
select displayName, tacticalParameter_id, b.value,datediff(DAY,convert(date,b.value,101),convert(date,getdate(),101)) as diff from EDA_TENANT1.EDA_T_P_A A, eda_tenant1.EDA_T_P_A_V b
where b.attribute_id = A.ID
and displayName like 'Fecha %'
and value <> '') X,
EDA_TENANT1.EDA_T_P C, EDA_TENANT1.EDA_TACT_P_G D
WHERE X.tacticalParameter_id = C.id
AND C.tacticalParameterGroup_id = D.id
and D.NAME in ('TPG Codigo postal - SPG Codigo postal',
'TPG Cuenta bancaria - SPG Cuenta bancaria',
'TPG Direccion - SPG Direccion',
'TPG Doc identidad - SPG Doc identidad',
'TPG Email - SPG Email',
'TPG Nombre - SPG Nombre',
'TPG Nombre empresa - SPG Nombre empresa',
'TPG Telf empresa - SPG Telf empresa',
'TPG Telf empresa movil - SPG Telf empresa movil',
'TPG Telf fijo - SPG Telf fijo',
'TPG Telf movil - SPG Telf movil',
'TPG Codigo agente - SPG Codigo agente',
'TPG Fiscal num - SPG Fiscal num')
Msg 241, Level 16, State 1, Line 1
Conversion failed when converting date and/or time from character string.
What could be the reason? Thanks!