473,386 Members | 1,793 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,386 software developers and data experts.

Make a copy of parts of a ROW, but with a new Key.

Hi there,

I want to insert a new record into my database table, giving new field
values for all but one (an image field), which I can copied from an existing
record. The background to this is that I am allowing a user to create a new
"template" from an existing one, thus I want a new record, but also to copy
the existing template data blob into the new record.

My code looks like this, but obviously doesn't work (I don't supply a field
for the first field "ID" in my SELECT statement which should be a unique ID.
Obviously, I want SQL to automatically generate one for me!). Is there any
way to do this with SQL?

IF @Error = 0
BEGIN
SELECT @DateCreated,
@Title,
@Description,
@Thumbnail,
ReportTemplate.Report

INTO

ReportTemplate

FROM

ReportTemplate

SET @Error = @@ERROR
END
Jul 20 '05 #1
1 3210
I think I got it. Like this:

IF @Error = 0
BEGIN
INSERT INTO
ReportTemplate
(
DateCreated,
Title,
Description,
IsStatic,
Thumbnail,
Report
)

SELECT

@DateCreated,
@Title,
@Description,
@IsStatic,
@Thumbnail,
ReportTemplate.Report

FROM

ReportTemplate

WHERE

ReportTemplate.ID = @ID

SET @Error = @@ERROR
END

"Robin Tucker" <id*************************@reallyidont.com> wrote in
message news:c6*******************@news.demon.co.uk...
Hi there,

I want to insert a new record into my database table, giving new field
values for all but one (an image field), which I can copied from an existing record. The background to this is that I am allowing a user to create a new "template" from an existing one, thus I want a new record, but also to copy the existing template data blob into the new record.

My code looks like this, but obviously doesn't work (I don't supply a field for the first field "ID" in my SELECT statement which should be a unique ID. Obviously, I want SQL to automatically generate one for me!). Is there any way to do this with SQL?

IF @Error = 0
BEGIN
SELECT @DateCreated,
@Title,
@Description,
@Thumbnail,
ReportTemplate.Report

INTO

ReportTemplate

FROM

ReportTemplate

SET @Error = @@ERROR
END

Jul 20 '05 #2

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

Similar topics

1
by: nic den | last post by:
Hi, I'm getting emails from an address trough a script and I want to copy the attached files on the server. I can get the files and copy them on the server (trough the function below) BUT the...
7
by: lawrence | last post by:
2 Questions: 1.) Can anyone think of a way to speed up this function? It is terribly slow. I plan to reduce the number of directories to 3, which I guess will speed it up in the end. 2.) This...
6
by: Maria L | last post by:
I have a client who needs to copy an existing sale. The problem is the Sale is made up of three tables: Sale, SaleEquipment, SaleParts. Each sale can have multiple pieces of equipment with...
3
by: Edwin Knoppert | last post by:
For near future specifications to place our ASP.NET software on a server not being ours i have to ask you a few rather simple questions. It's for professional use. We would not like to intervene...
6
by: scottyman | last post by:
I can't make this script work properly. I've gone as far as I can with it and the rest is out of my ability. I can do some html editing but I'm lost in the Java world. The script at the bottom of...
4
by: Chris F Clark | last post by:
Please excuse the length of this post, I am unfortunately long-winded, and don't know how to make my postings more brief. I have a C++ class library (and application generator, called Yacc++(r)...
19
by: Khafancoder | last post by:
Hi guys, in my db i have these three tables 1.Stores 2.Products 3.Parts their structure is something like : Stores ----Products ----Parts
82
by: Bill David | last post by:
SUBJECT: How to make this program more efficient? In my program, a thread will check update from server periodically and generate a stl::map for other part of this program to read data from....
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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.