Office

     Go!
Prospero Blocks


 

Chat Center

Board Folders

MS Office - General: 4363 msgs in 880 dscns, Latest: Nov-24 MS Office - Ge...
4363 msgs in 880 dscns
Latest: Nov-24
Outlook: 10271 msgs in 1964 dscns, Latest: 11:05 AMOutlook
10271 msgs in 1964 dscns
Latest: 11:05 AM
Word & Word VBA: 9371 msgs in 1768 dscns, Latest: 7:55 AMWord & Word VBA
9371 msgs in 1768 dscns
Latest: 7:55 AM
Excel & Excel VBA: 12863 msgs in 2269 dscns, Latest: 11:14 AMExcel & Excel VBA
12863 msgs in 2269 dscns
Latest: 11:14 AM
Powerpoint: 750 msgs in 196 dscns, Latest: Sep-18 Powerpoint
750 msgs in 196 dscns
Latest: Sep-18
Access & Access VBA: 5436 msgs in 1214 dscns, Latest: Nov-6 Access & Acces...
5436 msgs in 1214 dscns
Latest: Nov-6
Graphic Tools: 130 msgs in 34 dscns, Latest: Aug-25 Graphic Tools
130 msgs in 34 dscns
Latest: Aug-25
Publisher: 254 msgs in 47 dscns, Latest: Oct-18 Publisher
254 msgs in 47 dscns
Latest: Oct-18
Works Suite: 360 msgs in 73 dscns, Latest: 5/26/09 Works Suite
360 msgs in 73 dscns
Latest: 5/26/09
Money & MSTaxSaver: 97 msgs in 27 dscns, Latest: 12/25/08 Money & MSTaxS...
97 msgs in 27 dscns
Latest: 12/25/08
MS Maps & Trips: 78 msgs in 15 dscns, Latest: Oct-23 MS Maps & Trips
78 msgs in 15 dscns
Latest: Oct-23
FrontPage: 1259 msgs in 224 dscns, Latest: Oct-15 FrontPage
1259 msgs in 224 dscns
Latest: Oct-15
Other Office Products: 325 msgs in 82 dscns, Latest: Oct-29 Other Office P...
325 msgs in 82 dscns
Latest: Oct-29
OneNote: 144 msgs in 19 dscns, Latest: Nov-11 OneNote
144 msgs in 19 dscns
Latest: Nov-11
Message Area
Access & Access VBA

Select as category

 Subscribe SubscribeGet a printer-friendly version of this discussion Print Discussion 

#1 of 4

     Posted Oct-31 3:47 PM   
Carl Seiler/TX
 
From  Carl Seiler/TX  Posts 109  Last Nov-23
To  All      [Msg # 15891.1 ]    
Using Access 2007 (and 2002) as front-end for MS SQL Server database. This should be simple, but for some reason, I can't quite get it right.  We have a stored procedure that returns a table of 99 columns.  One of the columns has 12 different possible values that fit into 4 categories.  I need to do a report that groups them by these 4 categories, but these four categories don't appear in the results table.  I can't edit the stored procedure, so need to categorize the rows into each of the four categories based on the field.  Originally, I was going to do this using a CASE, but I find that Access apparently doesn't have a CASE in its SQL, so then I think I'll do a union, and have come up with:

SELECT *, "Type 1" AS category_type
FROM dbo_spresults
WHERE category_id = "CHS00001 USA1" or category_id ="I0213" or category_id ="MASI CHS 0001 US 09"
UNION
SELECT  *, "Type 2" AS category_type
FROM dbo_spresults
WHERE category_id = "CHS00003 USA1" or category_id = "82688" or category_id ="MASI CHS 0003 US 09"
UNION ALL
SELECT *, "Type 3" AS category_type
FROM dbo_spresults
WHERE category_id ="CHS00008 USA1" or category_id = "MASI CHS 0008 US 09" or category_id ="I0213-01"
UNION ALL
SELECT *, "Type 4" AS category_type
FROM dbo_spresults
WHERE category_id ="CHS00004 USA1" or category_id = "MASI CHS 0004 US 09" or category_id ="87470";


But when I run that query, I get a "Too many fields" error.  Grr.  What I find is that tables are limited to 256 fields, and even though mine only has 99, as soon as I add more than two of the categories above, I run into the error.  That is, I can do Type 1 UNION Type 2, but as soon as I add the UNION with Type 3, I get the error.  I'm guessing that there's a temporary table created that exceeds 256,  and even though my end result shouldn't exceed it, it doesn't like it.  So, I'm going to try and trim out some of the columns I don't need, but that's going to be difficult.  Is there an easier way.  Do I need to do this with nested Iif's in the SELECT?  What about other ways?

Carl
 OptionsReply to this Message Reply

#2 of 4

     Posted Oct-31 5:13 PM   
Carl Seiler/TX
 
From  Carl Seiler/TX  Posts 109  Last Nov-23
To  All      [Msg # 15891.2 Message 15891.2 replying to 15891.1 15891.1 ]    
OK, I did it with nested Iif's and ORs ala:

SELECT *, (Iif(category_id = "CHS00001 USA1" or category_id ="I0213" or category_id ="MASI CHS 0001 US 09","Type1",
               Iif(
category_id = "CHS00003 USA1" or category_id = "82688" or category_id ="MASI CHS 0003 US 09","Type 2",
                   Iif(
category_id ="CHS00008 USA1" or category_id = "MASI CHS 0008 US 09" or category_id ="I0213-01","Type 3",
                       Iif(
category_id ="CHS00004 USA1" or category_id = "MASI CHS 0004 US 09" or category_id ="87470","Type 4","Unknown")))))
AS category_type
FROM dbo_spresults;



Seems to be working so far.  A little tough to read though.  My indentation here is an attempt to clear that up a bit.  However, if there was some other recommended or more "obvious" way of doing this, I'd appreciate it.
 OptionsReply to this Message Reply

#3 of 4

     Posted Nov-1 3:40 AM   
Bill Manville
 
From  Bill Manville  Posts 4156  Last 5:35 AM
To  Carl Seiler/TX      [Msg # 15891.3 Message 15891.3 replying to 15891.2 15891.2 ]    

Where is this query being executed?  Since you are using IIf successfully I guess it's at the client.
I would use a local translation table MyCat containing Category_ID and Category_Type:

SELECT dbo_spresults.*, MyCat.Category_Type FROM dbo_spresults INNER JOIN MyCat ON dbo_spResults.Category_ID=MyCat.Category_Type.

Bill Manville
Excel MVP/TA
Oxford, England

 OptionsReply to this Message Reply

#4 of 4

     Posted Nov-2 11:52 AM   
Carl Seiler/TX
 
From  Carl Seiler/TX  Posts 109  Last Nov-23
To  Bill Manville      [Msg # 15891.4 Message 15891.4 replying to 15891.3 15891.3 ]    
I should have been a bit more clear about how this works.  VBA assembles a set of parameters that goes to a stored procedure which executes the query on MS SQL Server.  That query returns the results in a table (which I called dbo_spresults for stored procedure results).  From that query results table, I need to pull subset of records, and for that, I'm running my query in Access. 

Your solution sounds like a pretty good option, and I hadn't considered it as it is simply something I've never run into.

My solution is working pretty smoothly right now, although it's pretty ugly to read.  Your solution is much more elegant, and possibly clearer to someone coming back through and looking at what I've done.
 OptionsReply to this Message Reply
 Subscribe SubscribeGet a printer-friendly version of this discussion Print Discussion 
Access & Access VBA

Select as category

  
 
     

Welcome, Guest

  • Post a message
  • New messages to you
  • Log in

Start Search
Advanced Search

Prospero Blocks
 
 
Special Offers
 
 
 

Finding People

 
 
 

Cool Clicks!

 
 
 
© 2009 Netscape Communications Corp. All rights reserved.

Legal Notices | Privacy Policy