Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6192889
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:01:30+00:00 2026-05-24T03:01:30+00:00

I am getting a weird exception saying Msg 203, Level 16, State 2, Line

  • 0

I am getting a weird exception saying ”
“

Msg 203, Level 16, State 2, Line 53
The name 'SELECT 
        ISNULL(ESP.ID,-1) AS 'PayScaleID',
        ISNULL(E.Prefix,'') + ISNULL(E.SerialNo,0)   AS 'Token number',
        ISNULL(E.FirstName,'')+' '+ ISNULL(E.MiddleName,'')+' '+ISNULL(E.LastName,'') AS 'Employee name',   
        ISNULL(E.CostCentreCode,'') AS 'Cost centre code',
        ESP.TotalPresentDays AS 'Present days',
        ESP.TotalWeeklyOffDays AS 'Week offs',
        ESP.TotalPaidHolidays AS 'Paid holiDays',
        ESP.TotalAbsentDays AS 'Absent days',
        ESP.ArrearDays AS 'Arrear days',
        ESP.OTHours AS 'OTHours',
        ESP.TotalPaidAmount AS 'Total Amount',
        MAD.Name AS 'Allowance' ,
        X.Amount 
    INTO #temp
    FROM 
    (
        SELECT 
            -1 AS 'BillingI' is not a valid identifier."

I am executing the following query.
“

{

DECLARE @sql AS VARCHAR(8000)

SET @sql = 'SELECT 
        ISNULL(ESP.ID,-1) AS ''PayScaleID'',
        ISNULL(E.Prefix,'''') + ISNULL(E.SerialNo,0)   AS ''Token number'',
        ISNULL(E.FirstName,'''')+'' ''+ ISNULL(E.MiddleName,'''')+'' ''+ISNULL(E.LastName,'''') AS ''Employee name'',   
        ISNULL(E.CostCentreCode,'''') AS ''Cost centre code'',
        ESP.TotalPresentDays AS ''Present days'',
        ESP.TotalWeeklyOffDays AS ''Week offs'',
        ESP.TotalPaidHolidays AS ''Paid holiDays'',
        ESP.TotalAbsentDays AS ''Absent days'',
        ESP.ArrearDays AS ''Arrear days'',
        ESP.OTHours AS ''OTHours'',
        ESP.TotalPaidAmount AS ''Total Amount'',
        MAD.Name AS ''Allowance'' ,
        X.Amount 
    INTO #temp
    FROM 
    (
        SELECT 
            -1 AS ''BillingID'',
            ESP.ID AS ''EmployeeSalaryPaidID'',
            MAd.ID AS ''AllowanceID'',
            ESPD.PaidAmount AS ''Amount''
        FROM Employee_SalaryPaid ESP
        INNER JOIN Employee_SalaryPaidDetails ESPD ON ESPD.EmployeeSalaryPaidID = ESP.ID 
        INNER JOIN Employee E ON E.ID = ESP.EmployeeID 
        INNER JOIN Master_AllowanceDeduction MAD ON MAD.ID = ESPD.AllowanceDeductionID 
        WHERE ESP.YearAndMonth =201104
        UNION ALL
        SELECT
            CBR.ID AS ''BillingID'',
            CBRD.EmployeeSalaryPaidID,
            CBRD.AllowanceDeductionID AS ''AllowanceID'',
            CBRD.Amount AS ''Amount''

        FROM Company_BillRaised CBR
        INNER JOIN Company_BillRaisedDetails CBRD ON CBRD.BillRaisedID = CBR.ID
        WHERE CBR.MonthYear =201104
    )X 
    INNER JOIN Master_AllowanceDeduction MAD ON MAD.ID = X.AllowanceID
    INNER JOIN Employee_SalaryPaid ESP ON ESP.ID =X.EmployeeSalaryPaidID
    INNER JOIN Employee E ON E.ID= ESP.EmployeeID
    INNER JOIN dbo.vw_CompanyEmployeeIDs CE ON CE.EmployeeID = E.ID 
    WHERE CE.BranchID =73
DROP TABLE #temp'

 EXEC @sql 

}

I cannot understand what exactly the problem is? Do we have some limits of characters while executing Dynamic Sql like I am doing. I tried printing what I am getting in @Sql, I can get the results what I am looking for. But when I go like this using EXEC @Sql it gives me the error.

Any suggestions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:01:30+00:00Added an answer on May 24, 2026 at 3:01 am

    Try
    Declaring @sql as nvarchar(max)
    then

    exec sp_executesql @sql
    

    instead of

    exec @sql
    

    Executing dynamic sql with just exec is very limited. See this link http://www.sommarskog.se/dynamic_sql.html.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting a very weird exception when trying to deploy my app on JBOSS
I am getting a weird exception when I exit the program. This has started
For some reason in the testEmployee method I am getting weird error messages saying
We're getting this weird exception when trying to create a BitmapDecoder off an ASP.Net
We've been getting a weird exception from Hibernate trying to update a non-existent table.
I'm getting the following exception when calling 'GetProjectItemSummariesQuery' against my RIA Service. The weird
I am getting this weird exception and I have no clue how to figure
So a bit of a weird bug going on when getting a WM_KEYDOWN msg
I'm getting weird results from the System.out.print immediately below the Scanner declaration in the
I'm getting weird EXC_BAD_ACCESS errors. I thought that I didn't need to retain objects

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.