Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old March 21st, 2002, 05:24 PM
Hugh Hugh is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 6 Hugh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
How the **** do I do this?

Please forgive me if I'm being dense but I'm new to SQL.

How do I show a record more than once in the output of a select statement? There is a field in my table that contains a numeric value, I want to show the record this amount of times in my output. (if the value is 3 I want to see the record 3 times etc. - preferably displayed as 1 of 3, 2 of 3, 3 of 3)

How can I do this without creating temporary tables (restriction on the DB)?

Any help appreciated.

Reply With Quote
  #2  
Old March 21st, 2002, 07:22 PM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 12 m 16 sec
Reputation Power: 7
RE: How the **** do I do this?

Hmm..as for a straight SQL solution, I'm not sure. I sure can't think of anyway to do it....If you are going to be displaying the results with PHP or some other language like PHP, it can be done easily. If this is the case, let me know and I'll whip something up for you....


Reply With Quote
  #3  
Old March 22nd, 2002, 01:24 PM
Hugh Hugh is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 6 Hugh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: How the **** do I do this?

The problem is basically caused by the fact that we're using a reporting tool (business objects) to display the data. This generates the simple bits of the SQL but allows you to modify the SQL if you want to add anything a bit more complex. The data needs to be displayed on one of these reports so it does have to be an SQL solution.

Reply With Quote
  #4  
Old March 24th, 2002, 04:48 AM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 12 m 16 sec
Reputation Power: 7
RE: How the **** do I do this?

I've searched high and low for an answer on this...I just can't seem to come up with anything that doesn't utilize a temp table...what reporting software are you using? are you sure it's not possible to do this with the reporting software? If you have found an answer for this, please let me know what it is!

Reply With Quote
  #5  
Old March 26th, 2002, 01:05 PM
Hugh Hugh is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: UK
Posts: 6 Hugh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
RE: How the **** do I do this?

We have eventually got it to work, the solution is far from pretty though:

SELECT
ORDERS.OrderKey,
ORDERS.Door,
ORDERS.Route,
ORDERS.C_Company,
ORDERS.C_City,
ORDERS.ConsigneeKey,
ORDERS.StorerKey,
(SELECT COUNT(*) FROM LOC A WHERE A.LOC >= B.LOC) AS LabelNo
FROM LOC B, ORDERS
WHERE
(
ORDERS.ConsigneeKey != ' '
AND ORDERS.Route != '99 '
AND ORDERS.StorerKey = 'WHS '
AND ORDERS.Route != 'zz '
AND (SELECT COUNT(*) FROM LOC A WHERE A.LOC >= B.LOC) <= CONVERT(int, ORDERS.Route)
)
ORDER BY
ORDERS.OrderKey, LabelNo

We're only interested in the data from the ORDERS file but we bounce everything off the LOC file to give us our list of numbers (it could be any file that will always have a suitable number of records).

The following also worked in our 'play' environment but not in the live (Oracle vs SQL server):

SELECT
LABELS.DESCRIPTION,
Y,
LABELS.NOOFLABELS
FROM
LABELS,
(SELECT
COUNT(*) AS Y
FROM
LABELS A, LABELS B
WHERE
A.DESCRIPTION >= B.DESCRIPTION
GROUP BY
A.DESCRIPTION
ORDER BY 1)
WHERE Y <= LABELS.NOOFLABELS
ORDER BY LABELS.DESCRIPTION

It's a bit tidier but not a lot.

Hopefully you can make some sense of this and hopefully I won't need to do anything this weird again!

Thanks for your help and interest.

Reply With Quote
  #6  
Old March 27th, 2002, 06:39 AM
Matt Matt is offline
Contributing User
Codewalkers Specialist (4000 - 4499 posts)
 
Join Date: Apr 2007
Location: Florida
Posts: 4,158 Matt User rank is Private First Class (20 - 50 Reputation Level)Matt User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 h 12 m 16 sec
Reputation Power: 7
RE: How the **** do I do this?

Interesting...thanks for letting us know how you did it!


Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > How the **** do I do this?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 3 Hosted by Hostway
For more Enterprise Application Development news, visit eWeek