我想內部連接一個varchar字段上的smallint字段。我只需要整數值,但我得到一個錯誤。 varchar字段具有整數和字符串。我不需要ID字段只有DESC。內部連接轉換失敗
我得到一個錯誤:
Conversion failed when converting the varchar value 'AWOL' to data type smallint.
這是表的樣子:
==================================
|ID |DESC |
|==========|=====================|
|ACAMPROCAL|acamprosate calcium |
|----------|---------------------|
|BUPROPION |bupropion |
|----------|---------------------|
|1 |Other |
|----------|---------------------|
|4 |Expired |
|----------|---------------------|
|3 |Dschg |
|----------|---------------------|
|AWOL |Absence without Leave|
==================================
這裏是我做過嘗試,但也註釋掉查詢:
SELECT
CASE_NUM, LAST_NAME, FIRST_NAME, MI, '' AS NA,
DOB, SEX, [ADDRESS], '' AS NA, CITY, STATE, ZIP
--,CONVERT(SMALLINT, CONVERT(VARCHAR(55), CDTBL1.[DESC]))
--,CASE WHEN CDTBL1.ID BETWEEN 1 AND 99999 THEN CDTBL1.[DESC]
--END AS COUNTY
FROM
CDCLIENT
INNER JOIN
CDTBL1 ON CDCLIENT.ADDR_COUNTY_ID = CDTBL1.ID
你可以在連接的兩邊執行''varchar''嗎? – abhi