Problem in Dynamic sql

  • Hi all,

    When i try to add the '+@pDatabase+'.dbo. with the tablename in line 98,99,100 AM getting error like Msg 103,Msg 102,Msg 105 With out that Query running fine PLZ help me out on this.

    Query in Attachment.

    Regards,

    Basee

  • baseehkhan (4/29/2013)


    Hi all,

    When i try to add the '+@pDatabase+'.dbo. with the tablename in line 98,99,100 AM getting error like Msg 103,Msg 102,Msg 105 With out that Query running fine PLZ help me out on this.

    Query in Attachment.

    Regards,

    Basee

    What is the error you are getting?

    _______________________________________________________________

    Need help? Help us help you.

    Read the article at http://www.sqlservercentral.com/articles/Best+Practices/61537/ for best practices on asking questions.

    Need to split a string? Try Jeff Modens splitter http://www.sqlservercentral.com/articles/Tally+Table/72993/.

    Cross Tabs and Pivots, Part 1 – Converting Rows to Columns - http://www.sqlservercentral.com/articles/T-SQL/63681/
    Cross Tabs and Pivots, Part 2 - Dynamic Cross Tabs - http://www.sqlservercentral.com/articles/Crosstab/65048/
    Understanding and Using APPLY (Part 1) - http://www.sqlservercentral.com/articles/APPLY/69953/
    Understanding and Using APPLY (Part 2) - http://www.sqlservercentral.com/articles/APPLY/69954/

  • Please post the exact error message that you are getting.


    Kingston Dhasian

    How to post data/code on a forum to get the best help - Jeff Moden
    http://www.sqlservercentral.com/articles/Best+Practices/61537/

  • do a find and replace to add QUOTENAME, so you can accommodate weird database names with dashes/spaces

    FROM '+@pDatabase+'

    --should be

    FROM '+ QUOTENAME(@pDatabase) +'

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

  • Msg 103, Level 15, State 4, Line 106

    The identifier that starts with 'Dir Sales mACHOCodeLatestClear, mAC1CODELATESTCLEAR, mACDICodeLatestClear, mACSTCodeLatestClear, mPR3CodeLatestClear, mPR2CodeLa' is too long. Maximum length is 128.

    Msg 105, Level 15, State 1, Line 106

    Unclosed quotation mark after the character string 'Dir Sales mACHOCodeLatestClear, mAC1CODELATESTCLEAR, mACDICodeLatestClear, mACSTCodeLatestClear, mPR3CodeLatestClear, mPR2CodeLat'.

    Msg 102, Level 15, State 1, Line 106

    Incorrect syntax near 'Dir Sales mACHOCodeLatestClear, mAC1CODELATESTCLEAR, mACDICodeLatestClear, mACSTCodeLatestClear, mPR3CodeLatestClear, mPR2CodeLa'.

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply