以前我曾要求从字段中删除文本并将其转换为int,这可以成功运行.但是现在,我想对这个新值进行INNER JOIN.
所以我有这个:
SELECT CONVERT(int, SUBSTRING(accountingTab.id, PATINDEX('%[0-9]%', accountingTab.id), 999)) AS 'memId', userDetails.title, userDetails.lname FROM accountingTab INNER JOIN (SELECT id, title, first, last FROM memDetTab) AS userDetails ON memID = userDetails.id
然后我收到无效列名memID
错误.
我怎样才能解决这个问题?
您可以重复整个表达式或反转您的联接:
SELECT * FROM memDetTab JOIN (SELECT CONVERT(int, SUBSTRING(accountingTab.id, PATINDEX('%[0-9]%', accountingTab.id), 999)) AS 'memId', userDetails.title, userDetails.lname FROM accountingTab) subquery ON subquery.memID = memDetTab.ID