Unix Technical Forum

copying row from same table and adding value from form.request

This is a discussion on copying row from same table and adding value from form.request within the SQL Server forums, part of the Microsoft SQL Server category; --> I'm working on a way to copy most data columns from another row in the same table to a ...


Go Back   Unix Technical Forum > Database Server Software > Microsoft SQL Server > SQL Server

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-13-2008, 07:13 PM
ll
 
Posts: n/a
Default copying row from same table and adding value from form.request

I'm working on a way to copy most data columns from another row in the
same table to a new row and insert the courseID value from the form
that executes this action (the copy). Is it possible to have both
"values" and "select" in the same Insert Into statement?
Here's what I have (below). The "CopyCourseID" is the id of the
course that is copied to the new row, although the new row will have a
different course ID ("CourseID").
---------------------------------------------------------------

strCourseID=Request.Form("CourseID")
Insert table_a(CourseID,Name,Address)
Values(strCourseID)
Select Name, Address
From table_a
Where Course ID = Request.Form("CopyCourseID")
------------------------------------------------------------------

Thanks,
Louis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 05-13-2008, 07:13 PM
Roy Harvey (SQL Server MVP)
 
Posts: n/a
Default Re: copying row from same table and adding value from form.request

You can simply include the value in the SELECT list. A simplified
version, using constants, though you would use values from your
application.

INSERT table_a(CourseID,Name,Address)
SELECT 1234, Name, Address
FROM table_a
WHERE Course ID = 5678

Roy Harvey
Beacon Falls, CT

On Mon, 12 May 2008 12:38:51 -0700 (PDT), ll <barn104_1999@yahoo.com>
wrote:

>I'm working on a way to copy most data columns from another row in the
>same table to a new row and insert the courseID value from the form
>that executes this action (the copy). Is it possible to have both
>"values" and "select" in the same Insert Into statement?
>Here's what I have (below). The "CopyCourseID" is the id of the
>course that is copied to the new row, although the new row will have a
>different course ID ("CourseID").
>---------------------------------------------------------------
>
>strCourseID=Request.Form("CourseID")
>Insert table_a(CourseID,Name,Address)
>Values(strCourseID)
>Select Name, Address
>From table_a
>Where Course ID = Request.Form("CopyCourseID")
>------------------------------------------------------------------
>
>Thanks,
>Louis

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-16-2008, 02:39 PM
ll
 
Posts: n/a
Default Re: copying row from same table and adding value from form.request

On May 12, 3:27 pm, "Roy Harvey (SQL Server MVP)"
<roy_har...@snet.net> wrote:
> You can simply include the value in the SELECT list. A simplified
> version, using constants, though you would use values from your
> application.
>
> INSERT table_a(CourseID,Name,Address)
> SELECT 1234, Name, Address
> FROM table_a
> WHERE Course ID = 5678
>
> Roy Harvey
> Beacon Falls, CT
>
> On Mon, 12 May 2008 12:38:51 -0700 (PDT), ll <barn104_1...@yahoo.com>
> wrote:
>
> >I'm working on a way to copy most data columns from another row in the
> >same table to a new row and insert the courseID value from the form
> >that executes this action (the copy). Is it possible to have both
> >"values" and "select" in the same Insert Into statement?
> >Here's what I have (below). The "CopyCourseID" is the id of the
> >course that is copied to the new row, although the new row will have a
> >different course ID ("CourseID").
> >---------------------------------------------------------------

>
> >strCourseID=Request.Form("CourseID")
> >Insert table_a(CourseID,Name,Address)
> >Values(strCourseID)
> >Select Name, Address
> >From table_a
> >Where Course ID = Request.Form("CopyCourseID")
> >------------------------------------------------------------------

>
> >Thanks,
> >Louis



Thanks so much! This worked great.
Much appreciated,
Louis
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

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
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:55 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com