[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

Question
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.2

Querry Question

Asked by mguptill in MS SQL Server

Tags: Microsoft, SQL, 2000, Querry

When try to create this view I get this error Message.
Server: Msg 156, Level 15, State 1, Procedure casemanagement, Line 6
Incorrect syntax near the keyword 'DECLARE'.
I need the @FYearStart and @FYearEnd So I can Have the Fiscal year dates to be used in the Subqueries is thier a way to get this to work?
these are the Sub Queries that use the @FYearStart and @FYearEnd
--the snippet below contains the whole querry for the view.
(
select count (aw3.clientid_c)
from ar.activwork aw3
where aw3.attendance_c = '04'and aw3.activity_c = '171' and aw3.activitydate_d Between (@FYearStart) and (@FYearEnd)
and aw3.clientid_c = cl.uniqueid_c) as DNA_CM_Appointments ,
( select count (aw4.clientid_c)
from ar.activwork aw4
where aw4.attendance_c = '03'and aw4.activity_c = '171' and aw4.activitydate_d Between (@FYearStart) and (@FYearEnd)
and aw4.clientid_c = cl.uniqueid_c) as Staff_CM_Canceled_Appointments ,
( select count (aw5.clientid_c)
from ar.activwork aw5
where aw5.attendance_c = '02'and aw5.activity_c = '171' and aw5.activitydate_d Between (@FYearStart) and (@FYearEnd)
and aw5.clientid_c = cl.uniqueid_c) as Client_CM_Canceled_Appointments

1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
93:
94:
95:
96:
97:
98:
create view cd.casemanagement as
 
DECLARE @FYearStart datetime
-- the fiscal year starts on YYYY-07-01:
SET @FYearStart = convert (datetime, CAST(datepart(year, getdate()-365) as varchar(4)) + '-07-01', 120)
declare @FYearEnd datetime
-- the fiscal year ends on YYYY-06-30:
set @FYearEnd = convert (datetime , Cast(datepart(year,getdate())as varchar(4)) + '-06-30', 120)
select cl.uniqueid_c 'clientUniqueID', 
cl.clientcode_c 'ClientCode', cl.lastname_vc 'ClientLastName',
cl.firstname_vc 'ClientFirstName',cl.admdate_d,cl.termdate_d 'Termdate', 
cl.birthdate_d 'ClientBirthdate'
, (select datediff(YY, cl.birthdate_d, getDate()) -
      (case when (datepart(Y, cl.birthdate_d) > datepart(Y, getDate())) or
                  (datepart(Y, cl.birthdate_d) = datepart(Y, getDate()) And
                        datepart(Y, cl.birthdate_d) > datepart(Y, getDate()))
                  then 1
                  else 0
      end)) as 'Age'
, sm.uniqueid_c 'linkid',sm.Staffcode_c 'StaffCode',
sm.lastname_vc 'StaffLastName', sm.firstname_vc 'StaffFirstName'
 
 
,(
SELECT TOP 1 aw.activitydate_d  
    from ar.activwork aw
    where activity_c = '171'and attendance_c ='01'
        AND  aw.clientid_c = cl.uniqueid_c                  
      order by aw.activitydate_d desc) As LastCMDate 
,(
SELECT TOP 1 aw2.activitydate_d  
    from ar.activwork aw2
    where aw2.activity_c = '171'and aw2.attendance_c in ('98','99')
        AND  aw2.clientid_c = cl.uniqueid_c                  
      order by aw2.activitydate_d desc) As NextCMDate ,
 
( 
select count (aw3.clientid_c)
from ar.activwork aw3
where aw3.attendance_c = '04'and aw3.activity_c = '171' and aw3.activitydate_d Between (@FYearStart) and (@FYearEnd)
and aw3.clientid_c = cl.uniqueid_c) as DNA_CM_Appointments ,
( select count (aw4.clientid_c)
from ar.activwork aw4
where aw4.attendance_c = '03'and aw4.activity_c = '171' and aw4.activitydate_d Between (@FYearStart) and (@FYearEnd)
and aw4.clientid_c = cl.uniqueid_c) as Staff_CM_Canceled_Appointments ,
( select count (aw5.clientid_c)
from ar.activwork aw5
where aw5.attendance_c = '02'and aw5.activity_c = '171' and aw5.activitydate_d Between (@FYearStart) and (@FYearEnd)
and aw5.clientid_c = cl.uniqueid_c) as Client_CM_Canceled_Appointments 
 
,(
SELECT Top 1  CASE WHEN ps.pscode_c = '0005' THEN 'YES'  ELSE 'NO' END AS Medicaid_ins
   from cd.Client_Paysource ps
    where ps.pscode_c = '0005' and ps.enddate_d is null
        AND  ps.clientid_c = cl.uniqueid_c 
                ) As 'Medicaid_ins' ,
(
SELECT Top 1  CASE WHEN e.eligibility in( 'SPMI','SMI','LU','MASED','SED') THEN 'YES'  ELSE 'NO' END AS Medicaid_ins
   from cd.Client_elig_0n_activitydate e
    where e.eligibility in( 'SPMI','SMI','LU','MASED','SED')and e.activity_c = '171'and e.attendance_c ='01'
        AND  e.clientid_c = cl.uniqueid_c 
                ) As 'Eligible_on_171' 
,(select eligibility from cd.Client_Current_Eligibility e where e.uniqueid_c = cl.uniqueid_c) as CurrentElig
 
,(select top 1 aw10.activitydate_d 
 
from ar.activwork aw10
where aw10.clientid_c = cl.uniqueid_c and aw10.attendance_c = '01'
order by aw10.activitydate_d desc) as Last_activitydate,
 
(select top 1 aw12.activity_c 
from ar.activwork aw12
where aw12.clientid_c = cl.uniqueid_c and aw12.attendance_c = '01'
order by aw12.activitydate_d desc) as Last_activity,
 
 
(select top 1 ( sm2.firstname_vc + ' '+ sm2.lastname_vc) As Staff
from ar.activwork aw13
inner join ar.staffmaster sm2 on sm2.uniqueid_c = aw13.staffmasterid_c
where aw13.clientid_c = cl.uniqueid_c and aw13.attendance_c = '01'
order by aw13.activitydate_d desc) as Staffid_LastActv
 
 
 
 
 from ar.client cl
inner join cd.episode ep  on ep.clientid_c = cl.uniqueid_c
inner join cd.enrollments en on en.episodeid_c = ep.uniqueid_c
inner join ar.staffmaster sm on sm.uniqueid_c = ep.primstaffid_c
 
where --en.program_c = 'ESS' and 
en.enddate_d is null 
and cl.termdate_d is null and 
cl.clientcode_c --= '018833'
not like ('DS%') 
and cl.admstat_c not like ('A')and
ep.enddate_d is null and 
en.program_c not in ('199','499','104','499C','601','602','808','801')
[+][-]02/15/08 04:07 PM, ID: 20907177Accepted Solution

View this solution now by starting your 30-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

About this solution

Zone: MS SQL Server
Tags: Microsoft, SQL, 2000, Querry
Sign Up Now!
Solution Provided By: a1x
Participating Experts: 2
Solution Grade: A
 
[+][-]02/15/08 02:11 PM, ID: 20906503Expert Comment

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]02/15/08 02:45 PM, ID: 20906724Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]02/15/08 02:46 PM, ID: 20906731Author Comment

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 30-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-92 / EE_QW_2_20070628