473,387 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Tripling end results of a query

I need to add expense types to various projects in our ERP database. I
perform this query

select DISTINCT a.project_id
from project as a, project_cost_element as b
where a.project_id = b.project_id
and a.project_status in ('T','A')
and b.cost_element_id between '7012000' and '7012999'

The result is projects that this query is affected.

00010
00020
00162
00187
00242

I need to put this in a load file where for every 4 lines is the same project.
...I would like the end result

00010
00010
00010
00010
00020
00020
00020
00020
00162
00162
00162
00162
etc
--
Message posted via http://www.sqlmonster.com
Aug 17 '05 #1
4 1246
AK
create table seq(i int)
insert into seq values(1)
insert into seq values(2)
insert into seq values(3)
insert into seq values(4)
create table t(c char(2))
insert into t values('aa')
insert into t values('bb')
insert into t values('cc')
select c from t cross join seq
drop table seq
drop table t

c
----
aa
aa
aa
aa
bb
bb
bb
bb
cc
cc
cc
cc

(12 row(s) affected)

Aug 17 '05 #2
AK,

Thanks for the reponse a bit lost though, the project numbers are sometimes
not sequential.

i.e. it may go from 00010, 00020, but then jump to 00213, then 00457, etc...

Looking at the script on the insert values 'aa', I wouldn't be able to enter
these values (all 350 of them)

Jeff

AK wrote:
create table seq(i int)
insert into seq values(1)
insert into seq values(2)
insert into seq values(3)
insert into seq values(4)
create table t(c char(2))
insert into t values('aa')
insert into t values('bb')
insert into t values('cc')
select c from t cross join seq
drop table seq
drop table t

c
----
aa
aa
aa
aa
bb
bb
bb
bb
cc
cc
cc
cc

(12 row(s) affected)

--
Message posted via http://www.sqlmonster.com
Aug 17 '05 #3
Try this:

SELECT X.* FROM (
select DISTINCT a.project_id
from project as a, project_cost_element as b
where a.project_id = b.project_id
and a.project_status in ('T','A')
and b.cost_element_id between '7012000' and '7012999'
) X CROSS JOIN (
SELECT 1 N UNION SELECT 2 UNION SELECT 3 UNION SELECT 4
) Y

Razvan

Aug 17 '05 #4
Razan,

THANK YOU, this did it

Jeff

Razvan Socol wrote:
Try this:

SELECT X.* FROM (
select DISTINCT a.project_id
from project as a, project_cost_element as b
where a.project_id = b.project_id
and a.project_status in ('T','A')
and b.cost_element_id between '7012000' and '7012999'
) X CROSS JOIN (
SELECT 1 N UNION SELECT 2 UNION SELECT 3 UNION SELECT 4
) Y

Razvan

--
Message posted via http://www.sqlmonster.com
Aug 17 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

6
by: Francisco | last post by:
I have this question: I have a simple search to a db, something like: "select description from games where year = '1990'" suppose I get 300 results, I would like to display this in pages of 30...
6
by: paulus4605 | last post by:
Dears I have the following problem I’m using a query to get all the data from my database from the past year the second query is displaying the results by month. How can I match the second...
0
by: david liu | last post by:
access 2000 query: here's what i want to do. from an asp page, perform a search on a table in access. i have used sql code in the asp page itself, but i'd rather execute a query in access. i...
6
by: Alan | last post by:
I'm just about to start a project that needs to combine the results of a SQL Server query with the results of an Index Server query. The basic idea is that the user enters/selects a bunch of search...
8
by: san | last post by:
Hi, I wanted to know if this is possible and if so, how do I do it. Say, I have a query "SELECT * FROM Table WHERE Column="some_value". This executes on a very large data set and I would like...
3
by: Eli Criffield | last post by:
I'm getting odd results from my fuction that takes variable aguments. What i want to do is take a printf like format and pass that to mysql_query then i do some processing of the results and...
0
by: Rob | last post by:
I doubt this is the best way to do it, but what I came up with was to hide the XML in an HTML Comment then edit the file deleting the HTML stuff and keep the XML results. If anyone has a better...
9
by: Kelii | last post by:
I've been trying to get this piece to work for a few hours, but have given up. I hope someone out there can help, I think the issue is relatively straightforward, but being a novice, I'm stumped....
1
by: bgreenspan | last post by:
Hi Everyone, I'm back for some more expert help. Here's what I am doing and what I tried. My database has entries with Contract Names and Expiry Dates, among other fields. I have a form...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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...
0
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...

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.