Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 cast giving error

Author  Topic 

mary_itohan
Posting Yak Master

191 Posts

Posted - 2012-03-08 : 08:18:28
sorry what am i doing wrong here

SELECT     dbo.sub_categories.name +' '+ cast( COUNT(dbo.Training_courses.subcategoryID), as varchar(50)) AS Expr1, dbo.Training_courses.subcategoryID
FROM dbo.sub_categories INNER JOIN
dbo.Training_courses ON dbo.sub_categories.subcategoryID = dbo.Training_courses.subcategoryID
GROUP BY dbo.sub_categories.name, dbo.Training_courses.subcategoryID


Msg 156, Level 15, State 1, Line 1
Incorrect syntax near the keyword 'as'.


_____________________


Yes O !

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2012-03-08 : 08:40:28
Try removing the comma inside the cast

http://weblogs.sqlteam.com/jeffs/archive/2008/05/13/question-needed-not-answer.aspx
How to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-03-08 : 08:41:10
Remove the comma before the "AS VARCHAR(50)"
	dbo.sub_categories.name + ' ' + CAST(COUNT(dbo.Training_courses.subcategoryID) AS VARCHAR(50)) AS 
Go to Top of Page
   

- Advertisement -