sql server - Conversion failed when converting date and/or time from character string. UNION CTE -
i've been given view troubleshoot. begins cte gets values of surrogate key used in several tables unions between each query. uses cte inner join select data surrogate keys. query following code:
with emp ( select distinct employeesk view1 union select distinct employeesk table1 union --then there 2 views if include both, overall query fails select distinct employeesk view2 union select distinct employeesk view3 ) select col1, col2, col3 table2 t2 inner join emp on t2.employeesk = emp.employeesk
whenever use cte, users error:
msg 241, level 16, state 1, line 22 conversion failed when converting date and/or time character string.
if select each query separately returning ints. in fact, double checked each query running following query against each source:
select distinct sql_variant_property(<tablesk>, 'basetype') <source table or view>
all queries report columns returned int.
i have created #temptable:
create table #tmp ( surrogatekey int)
then inserted each query #temptable , inserts work. values ints. values range -1 16435.
i can queries work union long return 1 of 2 of queries. if remove either of these queries cte , union statements work, cannot use both. values these 2 queries ints , have values -1 16435 too.
i'm @ loss why error. other re-writing view stored procedure, , putting values temp table, try?
Comments
Post a Comment