469,110 Members | 1,894 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,110 developers. It's quick & easy.

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 3104
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 discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

6 posts views Thread by scottyman | last post: by
4 posts views Thread by Chris F Clark | last post: by
19 posts views Thread by Khafancoder | last post: by
82 posts views Thread by Bill David | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.