April 16, 2003 at 6:53 am
I've created a view using an EXISTS clause (One I've used in other views), when running the script to add the view I get the following error:
Server: Msg 913, Level 16, State 8, Line 4
Could not find database ID 102. Database may not be activated yet or may be in transition.
When I remove the EXISTS clause the view is added without issue. The query within the EXISTS clause is straight forward and doesn't contain any functions or subqueries.
Any help would be appreciated. Thanks!
April 16, 2003 at 6:58 am
Can you post the script that you used to create the view?
April 16, 2003 at 9:23 am
Here is the script to add the view. (sorry, couldn't figure out how to properly format with in the forum window, looks okay in posting window)
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
CREATE VIEW dbo.v_AC_from_NTFs
AS
SELECT tpc_cse_id AS case_id
, tpc_co_loc_cd AS comploc_cd
, tpc_creat_dt AS creat_dt
, tpc_cse_clos_dt AS clos_dt
, tpc.tpc_pars_emp_id AS pars_emp_id
, tpc.tpc_pars_ptnt_nbr AS pars_ptnt_nbr
, MIN(CASE
WHEN s.actul_srvc_strt_dt = '12/31/9999'
THEN s.expt_srvc_strt_dt
ELSE s.actul_srvc_strt_dt
END) AS first_admission_dt
, MAX(CASE
WHEN s.actul_srvc_strt_dt = '12/31/9999'
THEN s.expt_srvc_strt_dt
ELSE s.actul_srvc_strt_dt
END) AS last_admission_dt
FROM h_topcase tpc
INNER JOIN h_service s
ON s.cse_id = tpc.tpc_cse_id
AND s.pl_of_srvc_typ_cd = 'AH' -- Accute Hospital
AND s.clm_rmrk_cd <> 'ZZ' -- exclude cancelled services
AND s.srvc_detail_cd NOT IN ('06', '07') -- exclude psych & sub abuse
AND s.srvc_desc_cd = '02' -- Scheduled
AND s.srvc_seq_nbr = s.orig_srvc_seq_nbr
INNER JOIN h_notification n
ON tpc.tpc_cse_id = n.cse_id
AND n.ntf_recv_dt < CASE WHEN s.actul_srvc_strt_dt = '12/31/9999'
THEN s.expt_srvc_strt_dt
ELSE s.actul_srvc_strt_dt END
-- notification must have been received 3 or more days prior to the expected or actual service date
AND dbo.sp_work_days(n.ntf_recv_dt,CASE WHEN s.actul_srvc_strt_dt = '12/31/9999'
THEN s.expt_srvc_strt_dt
ELSE s.actul_srvc_strt_dt END) > 2
INNER JOIN d5434par_cc_case_activity a
ON tpc.tpc_cse_id = a.case_id
AND a.activity_typ_cd = '55' -- Transfer to Nursing Staff
-- activity must have been created prior to the expected or actual service date
AND a.creat_dt < CASE WHEN s.actul_srvc_strt_dt = '12/31/9999'
THEN s.expt_srvc_strt_dt
ELSE s.actul_srvc_strt_dt END
WHERE tpc.tpc_pgm_type = '07' -- Preservice
AND tpc.tpc_cse_sts_cd <> '1' -- exclude cancelled cases
AND EXISTS (SELECT *
FROM h_service s1
WHERE s1.cse_id = tpc.tpc_cse_id
AND s1.orig_srvc_seq_nbr = 1
-- CABG Codes
AND (s1.procedure_cd BETWEEN '33510' AND '33536'
OR s1.procedure_cd = '33572'
-- Back Surgery Codes
OR s1.procedure_cd BETWEEN '22840' AND '22852'
OR s1.procedure_cd = '22855'
-- Joint Replacement Codes
OR s1.procedure_cd IN ('27130', '27132', '27134', '27137', '27138',
'27284', '27286' , '27437', '27438', '28580')
OR s1.procedure_cd BETWEEN '27440' AND '27443'
OR s1.procedure_cd BETWEEN '27445' AND '27447'
OR s1.procedure_cd BETWEEN '27486' AND '27488'))
GROUP BY tpc_cse_id,
tpc_co_loc_cd,
tpc_creat_dt,
tpc_cse_clos_dt,
tpc.tpc_pars_emp_id,
tpc.tpc_pars_ptnt_nbr
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO
Viewing 3 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply