By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,363 Members | 1,470 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,363 IT Pros & Developers. It's quick & easy.

cannot change the type

P: 90
table 1: eno integer primary key,ename varchar(25),salary integer
table 2: dno integer primary key,eno integer references table1(eno),dname varchar(25)
when I give
select eno,ename,salary from table1
union
select eno,dno,dname from table2


it shows an error as
Syntax error converting the varchar value ' data in the column ' to a column of data type int.
how should I convert the data type
Jun 21 '08 #1
Share this Question
Share on Google+
1 Reply


ck9663
Expert 2.5K+
P: 2,878
table 1: eno integer primary key,ename varchar(25),salary integer
table 2: dno integer primary key,eno integer references table1(eno),dname varchar(25)
when I give
select eno,ename,salary from table1
union
select eno,dno,dname from table2


it shows an error as
Syntax error converting the varchar value ' data in the column ' to a column of data type int.
how should I convert the data type
when you do union, the sequence of the field list matters...the first select statement will be use to be the final table structure. in your case eno, ename and salary will be the final structure. the second select will be inserted on the first. so you are trying to insert dname to salary. by default, it would've explicitly convert columns...dno - to - ename is successfully converted since int can explicitly converted to varchar, but no the other way around. that's why your dname can not explicitly converted to salary.

happy coding

-- CK
Jun 21 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.