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
To recompile a view or procedure execute the following:
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.
You might also consider a DDL trigger to do this on demand.