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
精彩评论