473,833 Members | 2,199 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

SQL 2000 Adding a column identifier

28 New Member
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.S erviceOrders 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.BLSE IT 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 1453
iburyak
1,017 Recognized Expert Top Contributor
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 Recognized Expert Specialist
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
5803
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 information from MEMO fields within the Access 2000 database. I have not had any problems before displaying MEMO fields on NT and have tried various tips to resolve this issue but no luck so far. I was wondering if anyone had come accross a similar...
112
10374
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, share your experience in using IDENTITY as PK .
5
2052
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 dynamic content. Currently the database server houses all data pertinent to the organization (membership data, events, products, etc) in one database (~2.2 GB) as well as the web site content in a separate database (~40 MB). The web site pulls from...
3
17012
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=> alter table tickets add column rid serial; NOTICE: ALTER TABLE will create implicit sequence "tickets_rid_seq" for SERIAL column "tickets.rid" ERROR: adding columns with defaults is not implemented
3
2355
by: Steven Fox | last post by:
============================================================ About DB2 Administration Tools Environment ============================================================ DB2 administration tools level: Product identifier SQL08015 Level identifier 02060106 Level DB2 v8.1.5.449 Build level s040212 PTF WR21334...
6
4766
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 appreciated. Thanks in advance
2
3358
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 that column. I even want to sort up and down if one clicks again on the same header. No problem so far, all works well for one column. Now I want to sort on the first choosen column ASC or DESC and additionally on a second column ASC. I use the...
3
3227
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 code below is simply trying to load an empty table that has only three columns. In the code I set the Name and Type fields. The third column is a unique primary key set to Integer. I have set the Primary Key to Identity with a seed of 1 and...
12
6237
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 datagrid. Once I can get to that point I need some way to be able to add new data only to the new columns that were added. Here is some of my code: //Function For Importing Data From CSV File public DataSet ConnectCSV(string filetable)
0
9796
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9642
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10782
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10500
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10213
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9323
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6951
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5789
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
3078
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.