Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Implicit Conversoin error

Status
Not open for further replies.

t16turbo

Programmer
Mar 22, 2005
315
GB
hi there,

i'm trying to perform a union using the following SQL:
Code:
Select  ATEHistory.DepartCode, ATEHistory.TransDate, ATEHistory.Client+' - '+ ATEHistory.clntname,  rtrim(ATEHistory.lastname)+', '+rtrim(ATEHistory.firstname),rtrim(ATEHistory.EmplyCode), ATEHistory.description, ATEHistory.Quantity from dbo.ATEHistory 
UNION ALL 
SELECT  SUBSTRING(CLARITYHistory.DEPARTCODE, 3, 4), CLARITYHistory.PRSTART, CLARITYHistory.CUSTOMER_CODE+' - '+CLARITYHistory.CUSTOMER, CLARITYHistory.LAST_NAME+', '+CLARITYHistory.FIRST_NAME+' - '+CLARITYHistory.EXTERNAL_ID, CLARITYHistory.LOCATION, CLARITYHistory.ACTUALS  FROM dbo.CLARITYHistory

this complains of the error:
Code:
Server Message:  Number  257, Severity  16
Server 'dst_test', Line 1:
Implicit conversion from datatype 'TEXT' to 'VARCHAR' is not allowed.  Use the CONVERT function to run this query.

this only happened when I changed a value in the 2nd select from CLARITYHistory.PREXTERNALID to CLARITYHistory.EXTERNAL_ID.




can anyone tell me what might be happening.
shall I just use a convert function as the error message suggests?
can anyone tell me how.

thanks in advance,
Matt
 
just made a change to the first SELECT in the Union.
(I had change it to test some ideas)

here it is as it should be with the +' - '+ included

Code:
Select  ATEHistory.DepartCode, ATEHistory.TransDate, ATEHistory.Client+' - '+ ATEHistory.clntname,  rtrim(ATEHistory.lastname)+', '+rtrim(ATEHistory.firstname)+' - '+rtrim(ATEHistory.EmplyCode), ATEHistory.description, ATEHistory.Quantity from dbo.ATEHistory 
UNION ALL 
SELECT  SUBSTRING(CLARITYHistory.DEPARTCODE, 3, 4), CLARITYHistory.PRSTART, CLARITYHistory.CUSTOMER_CODE+' - '+CLARITYHistory.CUSTOMER, CLARITYHistory.LAST_NAME+', '+CLARITYHistory.FIRST_NAME+' - '+CLARITYHistory.EXTERNAL_ID, CLARITYHistory.LOCATION, CLARITYHistory.ACTUALS  FROM dbo.CLARITYHistory
 
Which column involved is the text column?

In general, a union query imposes the datatypes from the first query on the second query. So if you have

Code:
select charcol
from characters
union
select intcol
from numbers
order by 1
You will get the numbers ordered as if they were character strings. If you reverse the queries, you can get data type conversion errors.
 
thanks for that.

I used Convert on the second union to change EXTERNAL_ID to a varchar and it seems to have done the job.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top