Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

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

Options
  • 22-07-2008 4:01pm
    #1
    Registered Users 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 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 Posts: 68,317 ✭✭✭✭seamus


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


  • Registered Users 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 Posts: 68,317 ✭✭✭✭seamus


    Try this instead:

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


  • Registered Users Posts: 342 ✭✭adm


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


  • Advertisement
Advertisement