SELECT Skilled_Nursing_Visit_Note.ID, SNV_Printed_History.VendorsID, SNV_Printed_History.SNV_ID, Skilled_Nursing_Visit_Note.Client_Last_Name, Skilled_Nursing_Visit_Note.Nurse_Signature_Last_Name, Skilled_Nursing_Visit_Note.Visit_Date, Skilled_Nursing_Visit_Note.Shift_From_Hour, Skilled_Nursing_Visit_Note.Shift_To_Hour, Skilled_Nursing_Visit_Note.Date_Signed, Skilled_Nursing_Visit_Note.Nurse_Name_Stamp_SNV, Skilled_Nursing_Visit_Note.Nurse_User_ID_num_SNV, SNV_Printed_History.ReviewedBy, SNV_Printed_History.ReviewedDate, SNV_Printed_History.PrintedDate, SNV_Printed_History.PrintedBy, SNV_Printed_History.PrintedDate, Skilled_Nursing_Visit_Note.Client_First_Name, Skilled_Nursing_Visit_Note.Nurse_Signature_First_Name, Skilled_Nursing_Visit_Note.Date_Of_Birth, Skilled_Nursing_Visit_Note.Shift_From_Minute, Skilled_Nursing_Visit_Note.Shift_To_Minute, SNV_Printed_History.ReviewedDate, Skilled_Nursing_Visit_Note.Treatments_Administered, CInt(IIf([duration]=0,1440,[duration])/60) AS DurationHr, SNV_Printed_History.NoPrint, Skilled_Nursing_Visit_Note.Status, Skilled_Nursing_Visit_Note.Client_Last_Name_Init, Skilled_Nursing_Visit_Note.Visit_Date_Init, Skilled_Nursing_Visit_Note.Client_First_Name_Init, Skilled_Nursing_Visit_Note.Shift_From_Init, Skilled_Nursing_Visit_Note.Shift_To_Init, DLookUp("CountOfPN","SNVNotesQry","SNV_ID = '" & [Skilled_Nursing_Visit_Note].[SNV_ID] & "'") AS CountOfPN, DLookUp("CountOfNotes","SNVNotesQry","SNV_ID = '" & [Skilled_Nursing_Visit_Note].[SNV_ID] & "'") AS CountOfNotes, Int(Replace([Skilled_Nursing_Visit_Note].[SNV_ID],"snv","")) AS SNVNum, SNV_Printed_History.NoPrint, TimeValue(CDate(TimeSerial(Nz([Shift_To_Hour]),Nz([Shift_To_Minute]),0)-TimeSerial(Nz([Shift_From_Hour]),Nz([Shift_From_Minute]),0)+1))*24*60 AS Duration, (Abs(DateDiff("n",TimeSerial(Nz([Shift_From_Hour]),Nz([Shift_From_Minute]),0),TimeSerial(Nz([Shift_To_Hour]),Nz([Shift_To_Minute]),0)))/120)-Nz(DSum("CountOfNotes","SNVNotesQry","SNV_ID = '" & [Skilled_Nursing_Visit_Note].[SNV_ID] & "'"),0) AS MissingNotes, CInt(IIf([duration]=0,1440,[duration])/60) AS Duration2
FROM SNV_Printed_History INNER JOIN Skilled_Nursing_Visit_Note ON SNV_Printed_History.SNV_ID = Skilled_Nursing_Visit_Note.SNV_ID
ORDER BY Int(Replace([Skilled_Nursing_Visit_Note].[SNV_ID],"snv",""));
[ID] [int] IDENTITY PRIMARY KEY,
You can fix, but will have to drop the existing constraint first (yep, a primary key isnt just an index, it is a constraint) :
alter table Patient_Progress_Notes drop constraint PK_Patient_Progress_Notes;
GO
ALTER TABLE Patient_Progress_Notes ADD CONSTRAINT PK_Patient_Progress_Notes PRIMARY KEY CLUSTERED (id);
GO
select * from information_schema.KEY_COLUMN_USAGE where TABLE_NAME in ('Patient_Progress_Notes','Skilled_Nursing_Visit_Note','SNV_Printed_History')
We cannot create that view in SQL Server - not unless we convert the syntax to SQL Server.CREATE VIEW <view name> AS
select <column list>
from <tables>
See : https://docs.microsoft.com/en-us/sql/t-sql/statements/create-view-transact-sql?view=sql-server-2017 and scroll down to "Updatable Views". Then compare to : https://docs.microsoft.com/en-us/office/client-developer/access/desktop-database-reference/create-view-statement-microsoft-access-sql along with the same issues with an updateable view in Access as there is in SQL Server.Starting with the "SNVNotesQry": This should be converted into a SQL Server view. The main thing it does is adding all those non-normalized fields ending with "_x". So to makes this perform better you should create a persisted calculated column from it. Just go to the table designer and add the formula you used in the "SUM" function as a new column in the formula property. The datatype will automatically be set by SQL Server from the result of this formula so add a CONVERT function call if you want to have a specific datatype out of the result. Then set the formula to "Persisted", this will save the result value as a real table value into the table in this new column so it will be changed whenever one of the values of the source columns will be changed.Just to clarify, are you suggesting I first create a view and then a computed field, or the computed field approach is enough?
Just go to the table designer and add the formula you used in the "SUM" function as a new column in the formula property. The datatype will automatically be set by SQL Server from the result of this formulaThis formula field is something specific to SQL, guess would need to know more about it...
ALTER TABLE dbo.Patient_Progress_Notes
ADD CountOfNotes as (CASE
WHEN isnull(Patient_Progress_Notes_1,'') ='' THEN 0
ELSE 1
END)
Now I changed the formula to the following(case when [Status]='draft' then (0) else case when isnull([Patient_Progress_Notes_1],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_2],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_3],'')='' then (0) else (1) end +case when isnull([Patient_Progress_Notes_4],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_5],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_6],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_7],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_8],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_9],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_10],'')='' then (0) else (1) end + case when isnull([Patient_Progress_Notes_11],'')='' then (0) else (1) end end)
So this should take care of this column. CInt(IIf([duration]=0,1440,[duration])/60) AS DurationHr,
Int(Replace([Skilled_Nursing_Visit_Note].[SNV_ID],"snv","")) AS SNVNum, SNV_Printed_History.NoPrint,
TimeValue(CDate(TimeSerial(Nz([Shift_To_Hour]),Nz([Shift_To_Minute]),0)-TimeSerial(Nz([Shift_From_Hour]),Nz([Shift_From_Minute]),0)+1))*24*60 AS Duration,
(Abs(DateDiff("n",TimeSerial(Nz([Shift_From_Hour]),Nz([Shift_From_Minute]),0),TimeSerial(Nz([Shift_To_Hour]),Nz([Shift_To_Minute]),0)))/120)-Nz(DSum("CountOfNotes","SNVNotesQry","SNV_ID = '" & [Skilled_Nursing_Visit_Note].[SNV_ID] & "'"),0) AS MissingNotes, CInt(IIf([duration]=0,1440,[duration])/60) AS Duration2
Except for the DSUM which will be part of the table.But if you want, we can complete the conversion to SQL Server T-SQLThe problem with Access/SQL is that if you are still using any of the Access specific functions, it will force Access to load the entire recordset and be the one executing the query, which then nullifies the entire purpose of upgrading it to SQL.
Note in SQL2012 (and more recent) we do have IIF() and TIMEFROMPARTS() so that would take care of those few commands you highlighted above....
You could create a VIEW in MS Access as well..
Note in SQL2012 (and more recent) we do have IIF() and TIMEFROMPARTS()
You CAN update a view with JOINED tables in SQL Server
Also if we upgrade the servers SQL version to 2012, is mine personal SSMS 2008 pro edition still going to be able to connect to the DB of later version (if I download the free version I lose the profiler which is a very important tool)?If you can upgrade, go for a more actual version. E.g. JSON support in SQL Server 2016+, STRING_SPLIT().
Let me know if there is no way around, I will have to request management to upgrade to SQL 2012, but that may delay our processReason: Product life time.. End of Mainstream support for SQL Server 2008 and SQL Server 2008 R2.
create table [EE Test Table]
( ID AutoIncrement PRIMARY KEY,
int_Field1 Integer,
str_Field2 varchar(20)
);
Then go into Database Tools -> Visual Basic -> Immediate and type in :
currentproject.Connection.Execute "create view [vw EE Test Table] (F1,F2,F3) as SELECT ID, int_Field1, str_Field2 from [EE Test Table] AS EE"
Then close that window, and use the navigation pane to search for vw, It will find/ locate the query [vw EE Test Table]. Sure, it doesnt have the CREATE VIEW syntax, it has become a named / stored Query :
SELECT EE.ID AS F1, EE.int_Field1 AS F2, EE.str_Field2 AS F3
FROM [EE Test Table] AS EE;
Which is all a VIEW is anyway - a stored / named query. In that regard, Access has always had VIEWS - being a named query. So, it is the Query that needs to be updatable as far as Access is concerned.The task at hand is How To transition to a SQL Server backend, while using Access Syntax for Queries / Forms etc.
Because SQL Server wont support an updatable view/query the same way Access does when there are multiple tables....
Also I have to admit, that I don't understand your problem. The query contains a history table of some sort. These must are immutable. Thus the view must be immutable.
Again, I don't get it. The ETL process should normalize it. and when I read your mentioned thread, you should really invest some time in the data model. Cause under normal circumstances you need to modify it anyway to get the best of using SQL Server as backend. Especially as this is necessary to get the top performance from it.
Besides that, use always table alias names and prefix all column names with it. Currently it's unclear for the important columns in the formulas where they belong to. Which influences a possible solution.
Especially as it's currently not clear, whether you need an INSTEAD OF INSERT trigger to make this view updateable in Access. Here we need to know your data model around those tables and the desired workflow in Access.
btw, using Access and SQL Server requires imho that you make use of the (read-only) list and (updateable) edit form approach. Thus having different views for lists and the edit form.