Home Forums SQL Server 2008 T-SQL (SS2K8) error:- Unhandled Exception: System.Data.SqlClient.SqlException: Incorrect syntax near t he keyword 'as'.‌ RE: error:- Unhandled Exception: System.Data.SqlClient.SqlException: Incorrect syntax near t he keyword 'as'.?

  • Patrick.I - Saturday, February 3, 2018 6:07 AM

    HI All,
    I'm trying to use this sql query in my asp.net application but i keep getting error:-

    Unhandled Exception: System.Data.SqlClient.SqlException: Incorrect syntax near t
    he keyword 'as'.

       
    SqlCommand cmd = new SqlCommand("select DATENAME(month, GETDATE()) AS [month],month(getdate()) as [monthnumber],t1.Actual,t2.Target from (cast(round(sum(amountmst)/1000000,2) as decimal(10,2)) as [Actual] from trans where month(transdate) =month(getdate()) and year(transdate) = year(getdate()) and transtype=2 group by month(transdate)) as t1,
    (Select cast(round(sum(monthlybudget)/1000000,2) as decimal(10,2)) as [Target] from customer where month(date) = month(getdate()) and year(date)= year(getdate()) group by month(date)) as t2", con);

    I know this should be a stor proc but don't have access.
    Any ideas would be appreciated

    Could be that your SQL isn't even syntactically correct.