Hi makumbi,
First convert to VARCHAR value before Concatenate.
Please refer below sample query.
SQL
CREATE TABLE #StockKabojja
(
[Call] NVARCHAR(50),
[BookName] NVARCHAR(200),
[Author] NVARCHAR(50),
[BookCode] INT,
[AutoField] INT
)
INSERT INTO #StockKabojja VALUES('298.5', 'INTRODUCATION TO COMPUTER', 'MUKASA', 123, 1)
INSERT INTO #StockKabojja VALUES('500', 'CARTOONS MADE EASY', 'LUBEGA', 456, 2)
INSERT INTO #StockKabojja VALUES('632.5','INTRODUCATION TO READING','', 768, 3)
DECLARE @m NVARCHAR(50), @c NVARCHAR(50), @k INT
SET @k = 3
SET @c = '445'
SELECT @m= bookcode from #StockKabojja WHERE autofield=@k
IF ISNULL(@m,'') = ''
SELECT @m=CASE WHEN [Author] = '' THEN CONCAT(CONVERT(NVARCHAR(50),@c),SUBSTRING([BookName],1,3))
ELSE CONCAT(CONVERT(NVARCHAR(50),@c),SUBSTRING([Author],1,3)) END
FROM #StockKabojja WHERE autofield =@k
ELSE
SELECT @m=CASE WHEN [Author] = '' THEN CONCAT(CONVERT(NVARCHAR(50),[Bookcode]),SUBSTRING([BookName],1,3))
ELSE CONCAT(CONVERT(NVARCHAR(50),[Bookcode]),SUBSTRING([Author],1,3)) END
FROM #StockKabojja WHERE autofield =@k
SELECT @m
DROP TABLE #StockKabojja
Output