sql server - Adding another Table -
okay have made study calculating how many contracts funded in each month within year 2014.
so have calculate total contracts in service only.
what mean have table called tlkorigdept. within table have this
table tlkorigdept orig_dept_id orig_dept_name 1 sales 2 service 3 f&i 4 other 5 direct marketing
so have funded contracts service 'orig_dept_id' = 2 query problem see in clause. because when alter orig_dept_id 3 works not 2. shows blank , not error message.
the user inputs @begin_date , @end_date user picks company @program. user should see funded contracts each month service only.
i either see problem in select statement or clause
here query
[code="sql"] alter proc spgetadminserviceytd (@begin_date datetime, @end_date datetime, @program int=null) declare @year int set @year = 2014 declare @orig_dept_id int set @orig_dept_id = 2 begin select d.name, a.dealer_code, b.last_name, b.city, b.state, b.phone,e.orig_dept_name , count(case when month(c.orig_dept_id) = 1 1 else null end) jan , count(case when month(c.orig_dept_id) = 2 1 else null end) feburary , count(case when month(c.funded_date) = 3 1 else null end) march , count(case when month(c.funded_date) = 4 1 else null end) apr , count(case when month(c.funded_date) = 5 1 else null end) may , count(case when month(c.funded_date) = 6 1 else null end) june , count(case when month(c.funded_date) = 7 1 else null end) july , count(case when month(c.funded_date) = 8 1 else null end) august , count(case when month(c.funded_date) = 9 1 else null end) september , count(case when month(c.funded_date) = 10 1 else null end) oct , count(case when month(c.funded_date) = 11 1 else null end) nov , count(case when month(c.funded_date) = 12 1 else null end) dec , count(1) ytd tdealer bring together tcontact b on a.contact_id = b.contact_id bring together tcontract c on a.dealer_id = c.dealer_id bring together tcompany d on c.company_id = d.company bring together tlkorigdept e on c.orig_dept_id = e.orig_dept_id c.orig_dept_id = 2 , d.company_id = @program , c.funded_date >= dateadd(month, datediff(month, 0, getdate())-5, 0) , year(c.funded_date) = @year , c.funded_date < dateadd(month, datediff(month, -1, getdate())-1, 0) , (c.funded_date) between @begin_date , @end_date grouping d.name, a.dealer_code, b.last_name, b.city, b.state, b.phone, month(c.funded_date), month(e.orig_dept_name), e.orig_dept_name end exec spgetadminserviceytd '01/01/2014', '05/30/2014', '47'
sql-server where-clause
No comments:
Post a Comment