Solved

sql query and cfoutput

Posted on 2003-12-12
4
250 Views
Last Modified: 2013-12-24
I have a database as follows

ID      acccode          title                               set
1           A                 Header                           T
2           A1               sub heading                    T
3           A1333         company1                        T
4           A1335         company2                        Z

i need to output

HEADER

SUB HEADING

      company 1

I do not output company 2 as its code is Z


so far:
SELECT ACCNT_CODE , ACCNT_NAME
FROM  dbo.dbo_SSRFACC
WHERE SUSPEND <> 'Z'
ORDER BY ACCNT_CODE

doesnt work because of the WHERE clause for some reason, its a varchar

I can use multiple sql statements and loop over the sub departments and companies, can you please help

0
Comment
Question by:Ken-doh
4 Comments
 
LVL 4

Expert Comment

by:sandy12879
ID: 9927478
select  title from tablename  where set ='t'
0
 
LVL 11

Expert Comment

by:hart
ID: 9927744
how is that u have the main heading, sub heading and companies under these in the same table...

if u want just the first three records then what sandy wrote is fine just change
select  title from tablename  where set ='t'

to

select  title from tablename  where set ='T'
set is a database key word i think ur fieldname is SUSPEND  so it would be suspend = 'T'

or if u want to show the heading first then the sub heading and then list all the companies that come under these sub heading

Q1. will the acccode  for a heading be always 'A'
Q2. will the accode for a subheading be always 'A1'

see i would have kept a dept / heading table [with headingid and heading]
a sub department / sub heading table [with subheadingid and subheading ]

and in the other table i would have stored data as
headingid
subheadingid
company

this way by using joins i would have got the heading, sub heading and companies in one query..

Regards
Hart

0
 
LVL 1

Accepted Solution

by:
3gg earned 25 total points
ID: 9967196
This should get you started in the right direction. I don't have a debugger here to check this SQL, but you should be able to do this with MS-SQL Server 2000, mySQL and PostgreSQL. Oracle changes the function to SUBSTR()

<cfquery name="q" datasource="yourdatasource">
   SELECT SUBSTRING(acccode,1,1) AS groupA,
                SUBSTRING(acccode,1,2) AS groupB,
                title
   FROM dbo.dbo_SSRFACC
   WHERE suspend <> 'Z'
   GROUP BY acccode, title
   ORDER BY groupA, groupB
</cfquery>

<cfoutput query="q" group="groupA">
 <p>#q.groupA#</p>
 <cfoutput group="groupB">
  <p>#q.groupB#</p>
  <cfoutput>
   #q.title#<br />
  </cfoutput>
 </cfoutput>
</cfoutput>
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most ColdFusion developers get confused between the CFSet, Duplicate, and Structcopy methods of copying a Structure, especially which one to use when. This Article will explain the differences in the approaches with examples; therefore, after readin…
Introduction This article explores the design of a cache system that can improve the performance of a web site or web application.  The assumption is that the web site has many more “read” operations than “write” operations (this is commonly the ca…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

770 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