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 7864803
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:53:40+00:00 2026-06-02T23:53:40+00:00

I have a very unexpected affect on at view with named fields when adding

  • 0

I have a very unexpected affect on at view with named fields when adding columns to a table which the view depends upon.

SQL:

SELECT     dbo.AccessCustomFieldDepartment.AccessCustomFieldDepartmentID, dbo.AccessCustomFieldDepartment.AccessCustomField_StoreID, 
                      dbo.AccessCustomFieldDepartment.AccessCustomField_ShopOwner, dbo.AccessCustomFieldDepartment.AccessCustomField_CVRnumber, 
                      dbo.AccessCustomFieldDepartment.AccessCustomField_OpenMonToWed, dbo.AccessCustomFieldDepartment.AccessCustomField_OpenMonToThu, 
                      dbo.AccessCustomFieldDepartment.AccessCustomField_OpenMonToFri, dbo.AccessCustomFieldDepartment.AccessCustomField_OpenMonToTue,
--..
--a bunch of other fields
--..

                  dbo.AccessUser.AccessUserAddress, dbo.AccessUser.AccessUserAddress2, dbo.AccessUser.AccessUserZip, dbo.AccessUser.AccessUserCity, 
                  dbo.AccessUser.AccessUserCountry, dbo.AccessUser.AccessUserWeb
FROM         dbo.AccessUser INNER JOIN
                      dbo.AccessCustomFieldDepartment ON dbo.AccessUser.AccessUserID = dbo.AccessCustomFieldDepartment.AccessCustomFieldDepartmentID

When other peoples code does a dynamic add column to the table AccessUser, the server or something changes the sql of the view!

EG:

dbo.AccessUser.AccessUserCountry, dbo.AccessUser.AccessUserWeb

gets changed to

dbo.AccessUser.AccessUserCountry AS AccessUserCity, 
dbo.AccessUser.AccessUserWeb AS AccessUserCountry

This greatly F***s up my resulting presentation of the data….Its like the View tries to maintain the position of the respective columns.

Deleting the column magically changes the sql back to original.

So question is:

  • What is going on? Is it the server? Some functionality in the CMS
    software (where the add field function is)
  • Can I make a setting on the view to make it regard the sql statement 100% static?

Regards,

Steen

  • 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-06-02T23:53:42+00:00Added an answer on June 2, 2026 at 11:53 pm

    To recompile a view or procedure execute the following:

    /* View: */
    exec sp_refreshview 'dbo.MyViewName'
    
    /* Procedure, FN, IF, TF */
    exec sp_recompile 'dbo.ProcedureName'
    exec sp_recompile 'dbo.ScalarFunctionName'
    exec sp_recompile 'dbo.InlineFunctionName'
    exec sp_recompile 'dbo.TableFunctionName'
    

    You can get the list of objects from sysobjects. It should be relatively easy to select these into a table variable, and generate a loop which recompiles each one in turn.

    set nocount on
    declare @o table(
        id int primary key,
        object_full_name nvarchar(1000),
        xtype nvarchar(20)
    )
    insert @o
    select
        id, object_schema_name(id) + '.' + object_name(id) as object_full_name, xtype
    from sysobjects so 
    where 
        xtype in ('V', 'P', 'FN', 'TF', 'IF')
    
    
    while exists (select 1 from @o)
    begin
        declare @id int
        declare @object_full_name nvarchar(1000)
        declare @xtype nvarchar(20)
        set @id = null
        select top 1 @id = id, @object_full_name = object_full_name, @xtype = xtype from @o order by xtype, object_full_name, id
        delete @o where id = @id
        if @xtype = 'V'
        begin
            raiserror('Marking for recompile - %s: %s', 0, 1, @xtype, @object_full_name)
            exec dbo.sp_refreshview @object_full_name
        end
        else
        begin
            raiserror('Marking for recompile - %s: %s', 0, 1, @xtype, @object_full_name)
            exec dbo.sp_recompile @object_full_name
        end
    end
    

    You might also consider a DDL trigger to do this on demand.

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

Sidebar

Related Questions

I have a very simple query that's giving me unexpected results. Hints on where
I have tried my hand at some pagination but it gives me very unexpected
I have a very large object which I wish to serialize. During the process
I have a piece of code which works in a way that is unexpected
Ok, this is very unexpected and it annoys me. I have function called default()
I have very simple window where I have 2 buttons - one for cancel,
I have very little experience with ASP.NET and I am doing some self-training before
I have very little experience working with sockets and multithreaded programming so to learn
I have very little experience using Sharepoint but a good amount using Visual Studio
I have very long integer sequences that look like this (arbitrary length!): 0000000001110002220033333 Now

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.