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'.?

  • Sean Pearce - Sunday, February 4, 2018 5:00 AM

    There is a missing select, and no join condition for t1 and t2.
    SqlCommand cmd = new SqlCommand("
        select
            DATENAME(month, GETDATE()) AS [month],
            month(getdate()) as [monthnumber],
            t1.Actual,
            t2.Target
        from
            ( [NO SELECT HERE]
                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
    [NO JOIN CONDITION HERE]
    ", con);

    Actually, it is a Cartesian product (or cross join).