Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to get desired output using Stored Procedure

Author  Topic 

tsaliki
Starting Member

19 Posts

Posted - 2014-01-16 : 01:34:24
I have a table


Create table testmuljobs
(
AutoID int Identity(1,1),
JobID int not null,
AcctID int not null,
CreatedBy Varchar(100) null,
CreatedDate Datetime null,
ModifiedBy Varchar(100) null,
ModifiedDate Datetime null,
RecStatus bit null
)


and for CreatedDate and ModifiedDate i have Default Constraints

I want to insert records into that table with the help of sp as follows:
i will pass Jobid and Acctid .The Sample example stored procedure is


Create PROCEDURE [dbo].[TestMulJobsSave]
(
@JobID INT = Null,
@AcctID INT = Null,
@CreatedBy VARCHAR(100) = Null,
@ModifiedBy VARCHAR(100) = Null

)

AS

Begin


Insert into [TestMulJobs] (JobID,AcctID,CreatedBy,CreatedDate,ModifiedBy,ModifiedDate) Values

( @JobID,@AcctID,@CreatedBy,Getdate(),@ModifiedBy, Getdate() )


End


now when i execute the sp like for example TestMulJobsSave 5653,7 it is inserting the records and working fine,but my requirement is instead i want to insert as 5654-7, 5723-8, 5824-3,5654-7.All the above must be inserted as 4 records the first one is jobid and the corresponding to it is the AcctID i.e i want to insert multiple acctid and the corresponding jobiD at a time.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2014-01-16 : 05:15:30
you need to rewrite the procedure logic to accept multiple values. see links i posted in the other forum.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

rocknpop
Posting Yak Master

201 Posts

Posted - 2014-01-16 : 05:15:39
You have 3 options, google to find more on these:

1. Table Valued Parameters (TVP): pass one parameter as a TVP, this was introduced in sql 2008.
2. XML: build an xml and pass one parameter as an xml; xml data type was introduced in sql 2005
3. pass a comma separated string and use a function to split the string

--------------------
Rock n Roll with SQL
Go to Top of Page
   

- Advertisement -