troubleshooting Question

Looking to convert an Access query to MS SQL view.

Avatar of bfuchs
bfuchsFlag for United States of America asked on
DatabasesMicrosoft SQL ServerSQL
25 Comments3 Solutions228 ViewsLast Modified:
Hi Experts,

This question is in reference to the following
https://www.experts-exchange.com/questions/29126346/Help-needed-converting-Access-DB-to-MS-SQL-Server.html?anchor=a42738873¬ificationFollowed=218466827#a42738873

I'm looking to convert the following Access SQL query to a SQL server equivalent as a view.

View should be updatable and perform efficient as possible.

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",""));

Attaching the create tables script needed for those involved, including what SNVNotesQry does...

Note- tables are not in most normalized state, however structure cannot be changed, as data is being fed from another source...
1.txt
ASKER CERTIFIED SOLUTION
Bitsqueezer

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 3 Answers and 25 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 3 Answers and 25 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros