Incorrect syntax

  • I'm getting a incoorect sytax error when trying to ALTER a SP for my project.

    The error states that the sytax is not correct near the keyord 'ALL'

    Those are two single quotes as: ''All Suppliers'' AS CompanyName

    Here's my code:

    -- Set up parameter to control type of results to return

    -- Default value to 0 for only stored data

    @ReturnAllRow bit = 0

    AS

    -- Determine which version of the query will execute

    If @ReturnAllRow = 1 -- ''All Suppliers'' row to be included

    BEGIN

    ERROR>>>SELECT 0 AS SupplierID, ''All Suppliers'' AS CompanyName

    UNION

    SELECT SupplierID, CompanyName

    FROM Suppliers

    ORDER BY CompanyName

    END

    --No ''All Suppliers'' row to be returned

    Else

    BEGIN

    SELECT SupplierID, CompanyName

    FROM Suppliers

    ORDER BY CompanyName

  • anything in double quotes or square brackets are expected to be a column name, not a static value:

    SELECT 0 AS SupplierID, "All Suppliers" AS CompanyName

    --should be

    SELECT 0 AS SupplierID, 'All Suppliers' AS CompanyName

    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!

  • use 'All Suppliers' if its a static and use [All Suppliers] if its a column name

Viewing 3 posts - 1 through 3 (of 3 total)

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