Solved

sql query and cfoutput

Posted on 2003-12-12
4
248 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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
If you don't have the right permissions set for your WordPress location in IIS, you won't be able to perform automatic updates. Here's how to fix the problem.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

705 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

16 Experts available now in Live!

Get 1:1 Help Now