Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

I need to duplicte records in a table based on a field in the table

Status
Not open for further replies.

Timalaugh

Programmer
Aug 10, 2011
31
US
Hi all...
I have an odd one.
I need to be able to duplicate a record thisMany times where ThisMany is a field in the record. The table I start with only has one record. The problem is I need to do it in one select statement. Any one know how to do this.

thanks very much

Tim
 
Based on the information you've provided you have laid out mutually exclusive situations:

1: You have a functional requirement
2: You must use a specific tool

To accomplish your functional requirement, you want something like this:

Code:
Scatter Memo Memvar
For lnCount = 1 to table.Field 
  ** you said there was a field in the record 
  ** specifying the number of records to create.
  Insert into (Dbf()) From Memvar
Endfor

I'm not sure why you want to do this with a single Select statement. Select is usually used to query existing data.
 
Thanks but I need to do it in a single query.
This is in MS SQL Server and in the Report Builder so I need to do It an one select statement.
 
This is in MS SQL Server and in the Report Builder so I need to do It an one select statement

Perhaps if you explained more clearly why you think you need to do it in a single statement, then we could tell you that you were correct in your thought process or not.

And, then if not, we could advise you on alternative means to approach things.

Good Luck,
JRB-Bldr
 
As you talk of SQL Server: In any place you do a query you can also call a table valued function (user defined) and can do as much commands as needed to create the reulting data.

If you talk of foxpro reports, there even is less need to create the report driving data in one query.

I can also imagine you just post some test or exam question testing your knowlegde about T-SQL functionality enabling such query results.

Even takeing all that aside, you don't even specify what records you want generated. It would make sense to have meta data including a number of records eg for creating a number of identical labels, but what would not make any sense at all is, to multiply this meta data itself. Because then what do you end up with? The first record having some count field with 5, then creating 5 records each with a count of 5 (as you also copy that), and in the next step processing the 5 new records generating 5x5 further records? Where should that end? What would be the use of this?

I'd suggest you tell us the real world problem of what kind of report you want, and then we don't solve the step you're stuck with, but show you a completely new and hasssle free way to do this.

Bye, Olaf.
 
Hi,
Timalaugh

so you got it? Fine just dont tell us what please.

Jockey(2)
 
lol w/ Jockey2 :)


Ali Koumaiha
TeknoSoft Inc.
Michigan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top