Incorrect syntax near '/'

Posted on 2007-08-06
Last Modified: 2012-06-27
Having trouble with this sql

Set @Sql = 'Select Top ' + CAST(@T as varchar) + ' columns
From table
Where PageName = ' + @ScriptName + ' '

@ScriptName is the page currently on which may be "/account/index.cfm"
I get the error "Incorrect syntax near '/' "

Question by:dgrafx
    LVL 92

    Accepted Solution

    Set @Sql = 'Select Top ' + CAST(@T as varchar) + ' columns
    From table
    Where PageName = ''' + @ScriptName + ''' '

    LVL 75

    Expert Comment

    by:Aneesh Retnakaran
    Set @Sql = 'Select Top ' + CAST(@T as varchar) + ' columns
    From table
    Where PageName = ''' + @ScriptName + ''''
    LVL 142

    Expert Comment

    by:Guy Hengel [angelIII / a3]
    what version of SQL Server are you using?
    I ask, because with SQL 2005, you don't need the dynamic sql for the SELECT TOP @T  ... stuff...
    LVL 24

    Author Comment

    Thanks a lot
    angel - thats really interesting
    hope to move from 2000 to 2005 soon (I mean it's 2007!)

    Featured Post

    Do You Know the 4 Main Threat Actor Types?

    Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

    Join & Write a Comment

    Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
    For both online and offline retail, the cross-channel business is the most recent pattern in the B2C trade space.
    Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.
    Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now