Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Sql server field name issue (has a dot in it)

  • 22-07-2008 03:01PM
    #1
    Registered Users, Registered Users 2 Posts: 342 ✭✭


    Hi,
    I know very little about sql server but recently i've had to take
    over a very old very badly coded classic asp site that uses a sql server db.
    The site was recently a victim of those sql injection attacks that
    have been happening recently.

    I was able to clean out most of the database except for one table where some bright spark had put a dot (.) in the field names.
    So ,for example , one field is called DC.title and when i try to use REPLACE() on the the table i get an error.

    I don't have administrator access to the db as i'm on shared hosting so i cannot create a view to update the table.

    Is there any other way of doing it?

    Many thanks


Comments

  • Registered Users, Registered Users 2 Posts: 3,594 ✭✭✭forbairt


    adm wrote: »
    Hi,
    I know very little about sql server but recently i've had to take
    over a very old very badly coded classic asp site that uses a sql server db.
    The site was recently a victim of those sql injection attacks that
    have been happening recently.

    I was able to clean out most of the database except for one table where some bright spark had put a dot (.) in the field names.
    So ,for example , one field is called DC.title and when i try to use REPLACE() on the the table i get an error.

    I don't have administrator access to the db as i'm on shared hosting so i cannot create a view to update the table.

    Is there any other way of doing it?

    Many thanks

    You've put it in ''s ? when doing the replace ?


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    If the single quotes above doesn't work, try using square brackets [] to enclose the column name.


  • Registered Users, Registered Users 2 Posts: 342 ✭✭adm


    No sure what you mean?

    I tried this (works on other tables)

    Update table set DC.Title = REPLACE(DC.Title,'< bad code >','')

    DC.Title is the actual field name so i get an error. i presume cos it looks like an alias


  • Registered Users, Registered Users 2 Posts: 68,173 ✭✭✭✭seamus


    Try this instead:

    Update table set [DC.Title] = REPLACE([DC.Title],'< bad code >','')


  • Registered Users, Registered Users 2 Posts: 342 ✭✭adm


    cool thanks it worked.
    had to explicitly cast it also like so:
    REPLACE(Cast([DC.Title] AS NVARCHAR(Max)).....


  • Advertisement
Advertisement