473,414 Members | 1,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,414 software developers and data experts.

SQL 2000 Adding a column identifier

28
Hello everyone,

My query below works fine - but I'm having problems with identifying each of the 4 reports that are run in here. I need to have a column that has the name of the report run which are as follows: (This runs ALL at once)

1) Cable TV

2) Cable Modem

3) ADSL

4) Cingular

Each report is clearly listed below - but I just want to add something into my WHERE statement that would identify each report.



--============= Report for Cable TV, Cable Modem, ADSL and Cingular

SELECT COUNT(DISTINCT so.OrderType) AS Total, so.Order# AS OrderNumber, so.soCreated AS Order_Date, so.OrderType AS OType, sv7.InOut, IssuedByEmp#,



CASE IssuedbyEmp#
WHEN '201' THEN 'David Crosby'
WHEN '401' THEN 'Wanda Roberts'
WHEN '402' THEN 'Shirley Tisdale'
WHEN '406' THEN 'Betty Jo Broom'
WHEN '407' THEN 'Patricia Murphy'
WHEN '411' THEN 'Juli Christopher'
WHEN '412' THEN 'Tiawanna Dinkins'
WHEN '420' THEN 'Debbie Hoyle'
WHEN '424' THEN 'Mary Alice Brown'
WHEN '430' THEN 'Nicole Ramsey'
WHEN '432' THEN 'Gail Granger'
WHEN '438' THEN 'Tonya Wilks'
WHEN '463' THEN 'Karen Silvia'
WHEN '464' THEN 'Robin Gurganious'
WHEN '532' THEN 'Lori Miller'
WHEN '555' THEN 'Pam McBrayer'
WHEN '551' THEN 'Mary Ann Wilks'
WHEN '470' THEN 'Minnie Neal'
WHEN '471' THEN 'Cres Caldwell'
WHEN '477' THEN 'Amanda Peake'
WHEN '473' THEN 'Alice Holmes'
WHEN '450' THEN 'Lisa Kelly'
WHEN '474' THEN 'Gloria Langly'
WHEN '425' THEN 'Gene Underwood'
WHEN '469' THEN 'Mary Black'
WHEN '482' THEN 'Debra Singleton'
WHEN '480' THEN 'Jenifer Nelson'
WHEN '481' THEN 'Michael Davis'
WHEN '484' THEN 'Angie Devenport'
WHEN '422' THEN 'Richard Johnson'
WHEN '540' THEN 'Name Unknown'

END AS EmpName,



CASE so.OrderType
-- ========================================= Order Type (1)
WHEN 'NI' THEN 'New Install'
WHEN 'DS' THEN 'Disconnect'
WHEN 'RE' THEN 'Reconnect'
WHEN 'MI' THEN 'Misc Install'
WHEN 'CE' THEN 'Change Equipment'
WHEN 'BR' THEN 'Billing Record'
WHEN 'MR' THEN 'Misc Remove'
WHEN 'TR' THEN 'Transfer Service'
WHEN 'NC' THEN 'Number Change'
WHEN 'IN' THEN 'Internet'
WHEN 'NO' THEN 'Number Out'
WHEN 'DI' THEN 'Cing Activation'
WHEN 'DY' THEN 'Cing Reinstall'
WHEN 'CI' THEN 'Cing Port In'
WHEN 'DT' THEN 'Disconnect'

END AS Order_Type,


[Company] =
CASE
-- ============================================ Exchange (2)
WHEN so.PhoneNum LIKE '377%' THEN 'Chester'
WHEN so.PhoneNum LIKE '385%' THEN 'Chester'
WHEN so.PhoneNum LIKE '581%' THEN 'Chester'
WHEN so.PhoneNum LIKE '482%' THEN 'Great Falls'
WHEN so.PhoneNum LIKE '789%' THEN 'Chester'
WHEN so.PhoneNum LIKE '635%' THEN 'Fairfield'
WHEN so.PhoneNum LIKE '633%' THEN 'Fairfield'
WHEN so.PhoneNum LIKE '712%' THEN 'Fairfield'
WHEN so.PhoneNum LIKE '815%' THEN 'Fairfield'
WHEN so.PhoneNum LIKE '337%' THEN 'Ridgeway'
WHEN so.PhoneNum LIKE '338%' THEN 'Ridgeway'
WHEN so.PhoneNum LIKE '545%' THEN 'Lockhart'
WHEN so.PhoneNum LIKE '272%' THEN 'Camden'
WHEN so.PhoneNum LIKE '408%' THEN 'Camden'
WHEN so.PhoneNum LIKE '424%' THEN 'Camden'
WHEN so.PhoneNum LIKE '425%' THEN 'Camden'
WHEN so.PhoneNum LIKE '432%' THEN 'Camden'
WHEN so.PhoneNum LIKE '438%' THEN 'Camden'
WHEN so.PhoneNum LIKE '713%' THEN 'Camden'
--================================================== ================== Area code and Exchange (3)
WHEN so.PhoneNum LIKE '803377%' THEN 'Chester'
WHEN so.PhoneNum LIKE '803385%' THEN 'Chester'
WHEN so.PhoneNum LIKE '803581%' THEN 'Chester'
WHEN so.PhoneNum LIKE '803482%' THEN 'Chester'
WHEN so.PhoneNum LIKE '803789%' THEN 'Chester'
WHEN so.PhoneNum LIKE '803635%' THEN 'Fairfield'
WHEN so.PhoneNum LIKE '803633%' THEN 'Fairfield'
WHEN so.PhoneNum LIKE '803712%' THEN 'Fairfield'
WHEN so.PhoneNum LIKE '803815%' THEN 'Fairfield'
WHEN so.PhoneNum LIKE '803337%' THEN 'Ridgeway'
WHEN so.PhoneNum LIKE '803338%' THEN 'Ridgeway'
WHEN so.PhoneNum LIKE '803545%' THEN 'Lockhart'
WHEN so.PhoneNum LIKE '803272%' THEN 'Camden'
WHEN so.PhoneNum LIKE '803408%' THEN 'Camden'
WHEN so.PhoneNum LIKE '803424%' THEN 'Camden'
WHEN so.PhoneNum LIKE '803425%' THEN 'Camden'
WHEN so.PhoneNum LIKE '803432%' THEN 'Camden'
WHEN so.PhoneNum LIKE '803438%' THEN 'Camden'
WHEN so.PhoneNum LIKE '803713%' THEN 'Camden'
WHEN so.PhoneNum LIKE '803482%' THEN 'Great Falls'
--================================================== ================================Cable TV PhoneNumber (4)
WHEN so.PhoneNum LIKE '999%' THEN 'Chester'
WHEN so.PhoneNum LIKE '998%' THEN 'Camden'
WHEN so.PhoneNum LIKE '997%' THEN 'Great Falls'
WHEN so.PhoneNum LIKE '8030%' THEN 'Winnsboro'
WHEN so.PhoneNum LIKE '996%' THEN 'Chester'
---================================================== ==================== Bill Cycle (5)
WHEN so.BillCycle = '1' THEN 'Chester'
WHEN so.BillCycle = '7' THEN 'Chester'
WHEN so.BillCycle = '20' THEN 'Chester'
WHEN so.BillCycle = '21' THEN 'Chester'
WHEN so.BillCycle = '51' THEN 'Winsboro'
WHEN so.BillCycle = '81' THEN 'Camden'
WHEN so.BillCycle = '82' THEN 'Camden'

END,


CASE
WHEN sv7.InOut = 'I' THEN 'IN'
WHEN sv7.InOut = 'O' THEN 'OUT'
ELSE ' '

END AS In_Out




FROM ctcmaster.dbo.ServiceOrders AS so INNER JOIN
ctcsec.dbo.SV02 AS sv2 ON
so.order# = sv2.SV2SO# INNER JOIN
ctcsec.dbo.SV07 AS sv7 ON
so.order# = sv7.Order# INNER JOIN
ctcsec.dbo.BLSEIT AS bl
ON sv7.Item = bl.SEIITM LEFT JOIN
ctcsec.dbo.SV11 AS sv11 ON
so.Order# = sv11.S11SO#
--================================================== ================================================== ===================

--***************************
--- Cable TV WHERE ====> * <><><><><>----------->
--***************************


--*** Cable In

WHERE so.OrderType IN ('NI', 'RE') AND so.Status <> 'D' AND sv7.Status <> 'D' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.ITEM IN ('BNDMX', 'BNDST', 'BNDSH', 'BNDHB', 'BNDSP', 'BNDSN','MAXCH', 'STRCH', 'SHOWT', 'HBOCH', 'SPCHS', 'SNCHS', 'AA00', 'AA000', 'AA001', 'AA01', 'AA10', 'PRIME', 'AB00', 'AB01', 'AB10', 'FULL', 'FLCHS', 'TOTAL', 'TLCHS', 'HDALL' ) AND sv7.InOut = 'I'
AND so.soCreated BETWEEN '20070901' AND '20070930'
OR

---*** BVP In
so.OrderType IN ('NI', 'RE') AND so.Status <> 'D' AND sv7.Status <> 'D' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.ITEM LIKE 'BVP%' AND sv7.InOut = 'I' AND so.soCreated BETWEEN '20070901' AND '20070930'
AND so.soCreated BETWEEN '20070901' AND '20070930'
OR

---*** Cable Disconnect
so.OrderType = 'DS' AND so.Status <> 'D' AND sv7.Status <> 'D' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.ITEM IN ('BNDMX', 'BNDST', 'BNDSH', 'BNDHB', 'BNDSP', 'BNDSN','MAXCH', 'STRCH', 'SHOWT', 'HBOCH', 'SPCHS', 'SNCHS', 'AA00', 'AA000', 'AA001', 'AA01', 'AA10', 'PRIME', 'AB00', 'AB01', 'AB10', 'FULL', 'FLCHS', 'TOTAL', 'TLCHS', 'HDALL' ) AND sv7.InOut = 'O' AND so.soCreated BETWEEN '20070901' AND '20070930'
AND so.soCreated BETWEEN '20070901' AND '20070930'
OR


---*** BVP Disconnect
so.OrderType = 'DS' AND so.Status <> 'D' AND sv7.Status <> 'D' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.ITEM LIKE 'BVP%' AND sv7.InOut = 'O' AND so.soCreated BETWEEN '20070901' AND '20070930'
AND so.soCreated BETWEEN '20070901' AND '20070930'
OR

--================================================== ================================================== ===================

--***************************
--- Cable Modem WHERE ====> * <><><><><>----------->
--***************************

---*** CableModem In
so.OrderType IN ('CE', 'IN', 'NI', 'CE', 'IN', 'RE', 'MI', 'BR', 'NC') AND sv7.Status <> 'D' AND so.Status <> 'D' AND sv7.InOut = 'I' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.Item = bl.SEIITM AND bl.SEICLS = 'IT' AND bl.SEICAT = 'MD'
AND so.soCreated BETWEEN '20070901' AND '20070930'
OR

---*** CableModem Disconnect
so.OrderType = 'DS' AND sv7.Status <> 'D' AND so.Status <> 'D' AND sv7.InOut = 'O' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.Item = bl.SEIITM AND bl.SEICLS = 'IT' AND bl.SEICAT = 'MD'
AND so.soCreated BETWEEN '20070901' AND '20070930'
OR

---*** CableModem Out's
so.OrderType IN ('MI', 'MR', 'BR', 'CE', 'NC', 'NO') AND sv7.Status <> 'D' AND so.Status <> 'D' AND sv7.InOut = 'O' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.Item = bl.SEIITM AND bl.SEICLS = 'IT' AND bl.SEICAT = 'MD'
AND so.soCreated BETWEEN '20070901' AND '20070930'
OR

--================================================== ================================================== ===================

--*************************
---==== ADSL WHERE =====> * <><><><><>------------>
--*************************


---*** ADSL In
(sv7.Item IN ('ADSL')) AND (sv7.Status <> 'D') AND (so.Status <> 'D') AND (sv7.InOut = 'I') AND (so.OrderType IN ('NI', 'RE', 'MI', 'BR', 'CE')) AND (bl.SEITRF = ' ') AND
(bl.SEISTP = ' ') AND so.soCreated BETWEEN '20070901' AND '20070930'

OR

---*** ADSL Disconnect
(sv7.Item IN ('ADSL')) AND (sv7.Status <> 'D') AND (so.Status <> 'D') AND (sv7.InOut = 'O') AND (so.OrderType = 'DS') AND (bl.SEITRF = ' ') AND
(bl.SEISTP = ' ') AND so.soCreated BETWEEN '20070901' AND '20070930'
OR

---*** ADSL Out
(sv7.Item IN ('ADSL')) AND (sv7.Status <> 'D') AND (so.Status <> 'D') AND (sv7.InOut = 'O') AND (so.OrderType IN ('MR', 'CE', 'BR', 'MI')) AND
(bl.SEITRF = ' ') AND (bl.SEISTP = ' ') AND so.soCreated BETWEEN '20070901' AND '20070930'

OR

--================================================== ================================================== ===================

--****************
-- Cingular ===> * <><><><><>----------------->
--****************

---*** Cingular In
so.OrderType IN ('DI', 'DY', 'CI') AND sv7.Status <> 'D' AND so.Status <> 'D' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.InOut = 'I'
AND so.soCreated BETWEEN '20070901' AND '20070930'
OR

---*** Cingular Disconnects
so.OrderType IN ('DI', 'DY', 'CI', 'DT') AND sv7.Status <> 'D' AND so.Status <> 'D' AND bl.SEITRF = ' ' AND bl.SEISTP = ' ' AND sv7.InOut = 'O'
AND so.soCreated BETWEEN '20070901' AND '20070930'

--================================================== ================================================== ===================



GROUP BY IssuedbyEmp#, so.Order#, so.soCreated, so.OrderType, sv7.InOut, so.PhoneNum, so.BillCycle

ORDER BY sv7.InOut, so.soCreated, EmpName
Oct 16 '07 #1
2 1442
iburyak
1,017 Expert 512MB
Can you do separate reports or union first by each report which hardcode column marking report name and then group by?

Your group by mixes up all reports together.
Oct 16 '07 #2
ck9663
2,878 Expert 2GB
you might also want to use a table with emp# and name and just join it rather than have this long CASE WHEN.... code...you might have problem maintaining your code. this means whenever there are new employee, you have to fix your code

if you have a table, you just add new row on the emp table...

--CK
Oct 16 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

8
by: euang | last post by:
Hi, I have been using access 2000 for two years on WINDOWS NT to display dynamic aweb page using ASP My ISP has now changed to Windows 2003, and I am having major problems displaying...
112
by: Andy | last post by:
Hi All! We are doing new development for SQL Server 2000 and also moving from SQL 7.0 to SQL Server 2000. What are cons and pros for using IDENTITY property as PK in SQL SERVER 2000? Please,...
5
by: Lorax | last post by:
I'm on the IS team of a medium-sized non-profit with international reach. We're trying to make some decisions regarding our Web server and database server as we expand our web site to have more...
3
by: Claudio Lapidus | last post by:
Hello Now perhaps this is a bit dumb, but... I just populated a new table via \copy. After that, I realize that perhaps is a good thing to have a row identifier in it, so I try clapidus=>...
3
by: Steven Fox | last post by:
============================================================ About DB2 Administration Tools Environment ============================================================ DB2 administration tools level:...
6
by: Peter Frost | last post by:
Please help I don't know if this is possible but what I would really like to do is to use On Error Goto to capture the code that is being executed when an error occurs. Any help would be much...
2
by: Dutchy | last post by:
Hi there, After spending several hours trying all I could imagine and search for in Google I gave up. In a continuous form I want to sort the choosen column by clicking the header (label) of...
3
by: Hugh O | last post by:
Hi, I am not sure if this type of question should be raised in this Newsgroup. If not please direct me. I am new to using RDO.Net data access but I thought I understood it. The 6 lines of...
12
by: JMO | last post by:
I can import a csv file with no problem. I can also add columns to the datagrid upon import. I want to be able to start importing at the 3rd row. This will pick up the headers necessary for the...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.