SQL 2012 What am I doing wrong?

  • SELECT FirstName + '' + LastName AS 'Employee Name'

    FROM dbo.Employees

    ORDER BY STR (LEN(FirstName + '' + LastName))

    + STR (CHARIDEX('a', @Location;)+ RIGHT('SUBSTRING', 5);

    I keep getting and error message for the last line can you tell me what i am doing wrong...

  • richesflow (9/3/2012)


    SELECT FirstName + '' + LastName AS 'Employee Name'

    FROM dbo.Employees

    ORDER BY STR (LEN(FirstName + '' + LastName))

    + STR (CHARIDEX('a', @Location;)+ RIGHT('SUBSTRING', 5);

    I keep getting and error message for the last line can you tell me what i am doing wrong...

    How do you spell CHARIDEX correctly?

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • As Jeff poinged out you have a typo unless you were typing from memory and that's not how it is in your query. If that's the case, please let us know the exact error when you attempt to run your query.

    Mark

  • Sorry that was a typo... CHARINDEX

    I tryied CHAR INDEX as well but an error keeps coming up.

  • richesflow (9/3/2012)


    SELECT FirstName + '' + LastName AS 'Employee Name'

    FROM dbo.Employees

    ORDER BY STR (LEN(FirstName + '' + LastName))

    + STR (CHARIDEX('a', @Location;)+ RIGHT('SUBSTRING', 5);

    I keep getting and error message for the last line can you tell me what i am doing wrong...

    I guess there are few syntactical errors in above query.

    e.g.typo in CHARINDEX , syntax error in CHARINDEX (i.e. 😉 and also a closing bracket is required for STR.

    So please try out below query and if still no lock, please post the error message as well.

    SELECT FirstName + '' + LastName AS 'Employee Name'

    FROM dbo.Employees

    ORDER BY STR (LEN(FirstName + '' + LastName)) + STR (CHARINDEX('a', @Location)+ RIGHT('SUBSTRING', 5))

    --rhythmk
    ------------------------------------------------------------------
    To post your question use below link

    https://www.sqlservercentral.com/articles/forum-etiquette-how-to-post-datacode-on-a-forum-to-get-the-best-help
    🙂

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

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