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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to get desired output using Stored Procedure
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

tsaliki
Starting Member

India
19 Posts

Posted - 01/16/2014 :  01:34:24  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 01/16/2014 :  05:15:30  Show Profile  Reply with Quote
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 - 01/16/2014 :  05:15:39  Show Profile  Reply with Quote
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
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.4 seconds. Powered By: Snitz Forums 2000