DotNetNewsgroup.com  
web access to complete list of Microsoft.NET newsgroups
   home   |   control panel login   |   archive  |  
 
  carried group
academic
adonet
aspnet
aspnet.announcements
aspnet.buildingcontrols
aspnet.caching
aspnet.datagridcontrol
aspnet.mobile
aspnet.security
aspnet.webcontrols
aspnet.webservices
assignment_manager
datatools
dotnet.distributed_apps
dotnet.general
dotnet.myservices
dotnet.nternationalization
dotnet.scripting
dotnet.security
dotnet.vjsharp
dotnet.vsa
dotnet.xml
dotnetfaqs
framework
framework.clr
framework.compactframework
framework.component_services
framework.controls
framework.databinding
framework.drawing
framework.enhancements
framework.interop
framework.odbcnet
framework.performance
framework.remoting
framework.sdk
framework.setup
framework.webservices
framework.windowsforms
framework.wmi
frwk.windowsforms.designtime
lang.csharp
lang.jscript
lang.vb
lang.vb.controls
lang.vb.data
lang.vb.upgrade
lang.vc
lang.vc.libraries
  
 
start date: Fri, 17 Aug 2007 07:42:21 -0700,    posted on: microsoft.public.dotnet.framework.aspnet        back       

Thread Index
  1    JJ297
          2    bruce barker
          3    JJ297


Inserting into two tables   
how do I set up a stored procedure to insert into two tables.  This is
what I have thus far...

I want the quesid from the QuesNAns table to go into the Requestors
table  Getting an error message that I must declare the QuesID but
when I do it still does not work.  Any suggestions?


CREATE procedure AddQuestion

@quesdate datetime,
@topicid int,
@questions varchar(1000)


AS
Set NOCOUNT ON

INSERT INTO QuesNAns
(quesdate,topicid, questions)

values
(@quesdate,
@topicid,
@questions)

SET NOCOUNT OFF

SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]



INSERT INTO Requestors
(quesid)

values
(@quesid)

GO
Date:Fri, 17 Aug 2007 07:42:21 -0700   Author:  

Re: Inserting into two tables   
you seem a bit confused.

set nocount, controls whether transaction result counts are sent to the 
client. not sure why you turn it off and on. usually you turn it off to 
not get extra result sets. i assume @quesid is supposed to be the 
identity of the insert. instead of returning it to the caller, save it 
in a variable.


CREATE procedure AddQuestion
   @quesdate datetime,
   @topicid int,
   @questions varchar(1000)
AS
   Set NOCOUNT ON
   declare @quesid int

   INSERT INTO QuesNAns(quesdate,topicid, questions)
   values(@quesdate,
     @topicid,
     @questions)

   set @quesid = SCOPE_IDENTITY()

   INSERT INTO Requestors(quesid)
   values(@quesid)

   select @quesid as quesid -- return to caller if needed

GO


-- bruce (sqlwork.com)


JJ297 wrote:

> how do I set up a stored procedure to insert into two tables.  This is
> what I have thus far...
> 
> I want the quesid from the QuesNAns table to go into the Requestors
> table  Getting an error message that I must declare the QuesID but
> when I do it still does not work.  Any suggestions?
> 
> 
> CREATE procedure AddQuestion
> 
> @quesdate datetime,
> @topicid int,
> @questions varchar(1000)
> 
> 
> AS
> Set NOCOUNT ON
> 
> INSERT INTO QuesNAns
> (quesdate,topicid, questions)
> 
> values
> (@quesdate,
> @topicid,
> @questions)
> 
> SET NOCOUNT OFF
> 
> SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]
> 
> 
> 
> INSERT INTO Requestors
> (quesid)
> 
> values
> (@quesid)
> 
> GO
> 
Date:Fri, 17 Aug 2007 08:11:46 -0700   Author:  

Re: Inserting into two tables   
On Aug 17, 11:11 am, bruce barker  wrote:

> you seem a bit confused.
>
> set nocount, controls whether transaction result counts are sent to the
> client. not sure why you turn it off and on. usually you turn it off to
> not get extra result sets. i assume @quesid is supposed to be the
> identity of the insert. instead of returning it to the caller, save it
> in a variable.
>
> CREATE procedure AddQuestion
>    @quesdate datetime,
>    @topicid int,
>    @questions varchar(1000)
> AS
>    Set NOCOUNT ON
>    declare @quesid int
>
>    INSERT INTO QuesNAns(quesdate,topicid, questions)
>    values(@quesdate,
>      @topicid,
>      @questions)
>
>    set @quesid = SCOPE_IDENTITY()
>
>    INSERT INTO Requestors(quesid)
>    values(@quesid)
>
>    select @quesid as quesid -- return to caller if needed
>
> GO
>
> -- bruce (sqlwork.com)
>
>
>
> JJ297 wrote:
> > how do I set up a stored procedure to insert into two tables.  This is
> > what I have thus far...
>
> > I want the quesid from the QuesNAns table to go into the Requestors
> > table  Getting an error message that I must declare the QuesID but
> > when I do it still does not work.  Any suggestions?
>
> > CREATE procedure AddQuestion
>
> > @quesdate datetime,
> > @topicid int,
> > @questions varchar(1000)
>
> > AS
> > Set NOCOUNT ON
>
> > INSERT INTO QuesNAns
> > (quesdate,topicid, questions)
>
> > values
> > (@quesdate,
> > @topicid,
> > @questions)
>
> > SET NOCOUNT OFF
>
> > SELECT SCOPE_IDENTITY() AS [SCOPE_IDENTITY]
>
> > INSERT INTO Requestors
> > (quesid)
>
> > values
> > (@quesid)
>
> > GO- Hide quoted text -
>
> - Show quoted text -


Great thanks!
Date:Fri, 17 Aug 2007 08:27:27 -0700   Author:  

Google
 
Web dotnetnewsgroup.com


COPYRIGHT ?2005, EUROFRONT WORLDWIDE LTD., ALL RIGHT RESERVE  |   Contact us