Solved

SQL Query Help - Sum of Varchar

Posted on 2011-03-18
9
945 Views
Last Modified: 2012-05-11
Team,

Below is my query:


Declare  @Dates Varchar(255)
Set @Dates = ('WK10')

Select A.AcceptTeam, A.CreateDate, A.CharDate, a.Escalations, A.Abandons, a.Volume,  B.FiscalWk1 from
(select AcceptTeam, Convert(Datetime, CreateDate) as CreateDate
, Convert(Varchar(6), convert (datetime, CreateDate), 107) as CharDate
, count(*) Volume
, sum(case when CSIStatus = 'Escalation' then 1 else 0 end) escalations
, Sum(Case when TalismaStatus = 'Abandoned' then 1 else 0 end) Abandons
, TimeZone from Chat_Analyzed where ServiceLine = 'Celerra Support' and AcceptTeam <> 'Data Unavailable'
group by AcceptTeam, CreateDate, TimeZone) a
Inner Join
(Select FiscalDate, FiscalWK1 from reports.dbo.FiscalCalender) b
on a.CreateDate = b.FiscalDate
Where FiscalWK1 in (@Dates) and TimeZone = 'Amer'

Columns:
CSIStatus = Varchar(255)
TalismaStatus = Varchar(255)

When running the query, CSIStatus (Escalations) value is coming correctly however TalismaStatus(Abandons) is not showing any value. Just shows "0". However i do have some abandons for the running week.

Pls help
0
Comment
Question by:davidi1
  • 4
  • 4
9 Comments
 
LVL 39

Accepted Solution

by:
Pratima Pharande earned 500 total points
ID: 35164163
check the spell I thing it is wrong for Abandons
try this

, Sum(Case when TalismaStatus = 'Abandons' then 1 else 0 end) Abandons
0
 
LVL 9

Expert Comment

by:rajeevnandanmishra
ID: 35164164
Hi,
The query looks fine to me.
Though if you are not getting the required result, then please check:
1. The CreateDate column in Chat_Analyzed is having "time" value also?
2. The FiscalDate column in FiscalCalender is also having "time" or not?

It looks that for Escalations the data entered is without time. But for Abandons it is having time also. If such a scenario exists, then you need to use
Convert(Datetime, convert(varchar, CreateDate,111) ,111) as CreateDate
instead of
Convert(Datetime, CreateDate) as CreateDate
.

If not resolved, then please show us some sample data with columns properties.
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35164171
check the spell I thing it is wrong for Abandons
In query you have given 'Abandoned' and in Questin you asked for 'Abandons'
see which is correct and change accordingly

, Sum(Case when TalismaStatus = 'Abandons' then 1 else 0 end) Abandons
0
 
LVL 2

Author Comment

by:davidi1
ID: 35164186
@Pratima_mcs - Spelling is correct. "Abandoned" is how the data is in the table.

@Rajeev -

CreateDate column doesnt have time value in it.

This is how the table looks

CreateDate      TalismaStatus      CSIStatus
2/27/2011      Abandoned      Cancelled
2/27/2011      Complete              Cancelled
2/27/2011      Complete              Cancelled
2/27/2011      Complete              Closed
2/27/2011      Complete              Closed
2/27/2011      Abandoned      Cancelled


All the columns are Varchar in the table.

0
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35164219
what output you are getting here

Select A.AcceptTeam, A.CreateDate, A.CharDate, a.Escalations, A.Abandons, a.Volume,  B.FiscalWk1 from
(select AcceptTeam, Convert(Datetime, CreateDate) as CreateDate
, Convert(Varchar(6), convert (datetime, CreateDate), 107) as CharDate
, count(*) Volume
, sum(case when CSIStatus = 'Escalation' then 1 else 0 end) escalations
, Sum(Case when TalismaStatus = 'Abandoned' then 1 else 0 end) Abandons
, TimeZone from Chat_Analyzed where ServiceLine = 'Celerra Support' and AcceptTeam <> 'Data Unavailable'
group by AcceptTeam, CreateDate, TimeZone) a
Inner Join
(Select FiscalDate, FiscalWK1 from reports.dbo.FiscalCalender) b
on a.CreateDate = b.FiscalDate
0
 
LVL 2

Author Comment

by:davidi1
ID: 35164274
Result file uploaded.

Even in the output,

All the other values are correct except "Abandoned" value
Result.xlsx
0
 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 35164288
try with like

, Sum(Case when TalismaStatus like 'Abandoned' then 1 else 0 end) Abandons

or with ltrim and rtrim .. might it will have spaces

, Sum(Case when ltrim(rtrim(TalismaStatus)) = 'Abandoned' then 1 else 0 end) Abandons
0
 
LVL 2

Author Comment

by:davidi1
ID: 35164312
When I run the first query, "Escalations" value also getting changed.

& the second query - no difference with the original value(ie., abandoned column still a zero)
Result---1st-Query.JPG
0
 
LVL 2

Author Comment

by:davidi1
ID: 35164389
Pratima - I'll give you points. My bad.., TeamName wasnt coming for Abandoned cases.., hence it was showing "0". Thanks
0

Featured Post

Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

Join & Write a Comment

Naughty Me. While I was changing the database name from DB1 to DB_PROD1 (yep it's not real database name ^v^), I changed the database name and notified my application fellows that I did it. They turn on the application, and everything is working. A …
Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now