开发者

Not able to merge two columns in SQL Server while printing

I want to print two columns of a table in a desired format. I tried with the below format but it's giving error saying

开发者_运维百科

Error converting data type varchar to bigint.

This is my query:

Select  ClassID + ' .' + ClassSectionID AS Class 
from ClassSectionMaster  
ORDER BY Class

Can anybody tell me how to do this?


SQL Server doesn't like the fact you're trying to combine a column of type bigint (ClassID/ClassSectionID) with a string, ' .'

I'm assuming you want the output to be formatted like "9.6" and that strings are acceptable.

You have to use CAST or CONVERT to change the datatype to VARCHAR(x) to do this sort of combination.

SELECT CAST(ClassID AS VARCHAR(x)) + ' .' + CAST(ClassSectionID AS VARCHAR(y)) 
    AS Class
FROM ClassSectionMaster ORDER BY Class


Select (Convert(nvarchar(10), ClassID) + ' .' + Convert(nvarchar(10), ClassSectionID)) AS Class 
from ClassSectionMaster  
ORDER BY Class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜