Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7007825
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:39:25+00:00 2026-05-27T21:39:25+00:00

Running SQL Server 2005. A piece of software integrates with our database. Unfortunately they

  • 0

Running SQL Server 2005. A piece of software integrates with our database. Unfortunately they chose to make direct SQL queries instead of using stored procedures. Now we have changed our database scheme and the query in question is no longer valid.

Is it possible to patch T-SQL in runtime, on SQL Server?

E.g.
When SQL Server gets a SELECT A FROM InvalidTable for a specific database, the query would be converted to SELECT A FROM ValidTable just before it gets executed.

Edit:
This is the query in question:

SELECT * FROM DataTable c JOIN Users u ON u.UserName = @P0 AND c.DepartmentID = b2.DepartmentID WHERE c.Status = 0 where DepartmentID has moved to another table!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T21:39:26+00:00Added an answer on May 27, 2026 at 9:39 pm

    You can use Views and Synonyms to hide schema changes.

    So for simple things (like InvalidTable is now ValidTable), you can define a synonym

    CREATE SYNONYM InvalidTable FOR CorrectSchema.ValidTable;
    

    For more complex things (columns, JOINs, table splits, data types etc) you need a view

    CREATE VIEW InvalidTable 
    AS
    SELECT 
       col1, col2, 
       CAST(col3 AS varchar(1000)) AS col3, -- fix data type
       1 AS col4  -- not used now, but expected in legacy calls
    FROM
       CorrectSchema.ValidTable
    WHERE
       col5 = 'Something'
    GO
    

    Edit, after OP realises they’ve bollixed themselves

    You can’t have a view or synonym if a table exists with the same name in the same database.

    So, use another DB and make the legacy app use that instead. In the examples, you’d have DataTable in another db with the assumption you can use another DB withoout changing code

    USE legacyDB
    GO
    CREATE VIEW DataTable
    AS
    SELECT
       *
    FROM
       CorrectDB.CorrectSchema.ValidTable V
       JOIN
       CorrectDB.CorrectSchema.OtherTable O ON ...
    GO
    

    Otherwise, rename the correct DB and point all non-legacy code to the renamed DB.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We're running our application's database on dedicated box running only SQL Server 2005. This
I have a database running under Sql server 2005 with merge replication. I want
I have a SQL DTS package running on a SQL Server 2005 database that,
Running sql server 2005 I have database A. I am trying to restore from
I have two database servers running SQL Server 2005 Enterprise that I want to
I have been running SQL Server 2005 Express Management Studio (SSMSE), and I now
I'm running SQL Server 2005 Express. And I'm trying to do a bulk insert/import
We have a Windows machine running SQL Server 2005, and we need to be
We've got a web system running SQL Server 2005 for the back end, and
For one of my applications, I'm running SQL Server 2005, and I'm running it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.