Click here to Skip to main content
15,886,724 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
SELECT 
    F_TARIFGAM.TG_Prix, F_TARIFGAM.TG_RefCF, F_TARIFGAM.AR_Ref, 
    P_CATTARIF.CT_Intitule, P_CATTARIF.cbIndice
FROM 
    F_TARIFGAM 
INNER JOIN
    P_CATTARIF ON F_TARIFGAM.cbMarq = P_CATTARIF.cbMarq
WHERE 
     
    F_TARIFGAM.TG_RefCF = P_CATTARIF.cbIndice


What I have tried:

CAST(P_CATTARIF.cbIndice AS VARCHAR) or
CONVERT (VARCHAR() , P_CATTARIF.cbIndice)
Posted
Updated 29-Oct-19 21:34pm
v2
Comments
Afzaal Ahmad Zeeshan 29-Oct-19 6:41am    
What error do you get?
stephan20 29-Oct-19 6:56am    
error converting datatype varchar to smallint .F_TARIFGAM.TG_RefCF datatype 'varchar' and P_CATTARIF.cbIndice 'datatype smallint'
Richard Deeming 29-Oct-19 8:39am    
Where did you put the CAST? It will need to be in the WHERE clause:
WHERE F_TARIFGAM.TG_RefCF = CAST(P_CATTARIF.cbIndice As varchar(20))
stephan20 29-Oct-19 9:03am    
yes it work but didn't give me any data ??
Richard Deeming 29-Oct-19 10:38am    
Then the data in your tables isn't what you think it is.

We can't see your data, so we can't tell you what the problem is.

Try selecting the data from both tables separately and comparing the columns you're joining on to see why they don't match.

1 solution

You cannot cast a VARCHAR (which is an array of characters) to a SMALLINT, they are totally different objects. You must use a converter, as the VARCHAR object could contain anything.

See Richard Deeming's comment below.

[edit]
No idea what happened to all the comments, but Richard pointed out the the SQL CAST function does convert values.
[/edit]
 
Share this answer
 
v3
Comments
stephan20 29-Oct-19 7:46am    
can show me where and how to use CONVERT in script . thank you
Richard Deeming 29-Oct-19 8:37am    
SQL's CAST function[^] will let you do precisely that, and will throw an error if the string isn't a valid number.
Richard MacCutchan 29-Oct-19 9:35am    
Thanks for clarifying.
stephan20 29-Oct-19 9:23am    
so how about CONVERT .how to use it . thank you

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900