我的SQL查询中存在一些问题。表名为 debitorders ,其中包含以下列:
这是我们目前的查询:
SET @BankName = 'ABSA'
--SET @BankName = 'First National Bank'
SET @QueryResultA = (SELECT CASE @BankName
WHEN 'ABSA' THEN 'ABSA 0040000146162'
WHEN 'First National Bank' THEN 'First National B0020000045603'
END)
--PRINT @QueryResultA
SET @Amount = (SELECT amount FROM debitorders)
SELECT
left(LTRIM(RTRIM(firstname)),1) + '' + CONVERT (varchar(15),LTRIM(RTRIM(surname)),1),
(SELECT left(cast(LTRIM(RTRIM(accountnumber)) as varchar(14))+replicate(' ',14),14) ),
CASE accounttype
WHEN 'cheque'
THEN left(cast('CH' as varchar(3))+replicate(' ',3),3)
WHEN 'savings'
THEN left(cast('SAV' as varchar(3))+replicate(' ',3),3)
WHEN 'credit card'
THEN left(cast('CC' as varchar(3))+replicate(' ',3),3)
WHEN 'other'
THEN left(cast('OTH' as varchar(3))+replicate(' ',3),3)
END,
left(cast(LTRIM(RTRIM(branch)) as varchar(10))+replicate(' ',10),10),
REPLICATE('0', 7 - DATALENGTH (REPLACE(amount,'.',''))) + LTRIM(RTRIM(REPLACE(amount,'.',''))),
REPLACE(CONVERT(VARCHAR, date,103),'/','') AS DebitDate
--REPLACE(CONVERT(VARCHAR(10), date, 104) AS [DD.YYYY.MM]),'.',''
FROM debitorders
WHERE bankname = @BankName
结果应为:
为什么不识别列?
答案 0 :(得分:0)
您需要声明变量:
DECLARE @BankName VARCHAR(50) = 'ABSA';
您还尝试在@Amount变量中设置多个记录。你需要聚合吗?
答案 1 :(得分:0)
您是否针对正确的数据库运行查询?你的债务人表在哪里创建了?
我想首先检查一下你是不是在对master数据库运行查询。