Click here to Skip to main content
15,896,329 members
Home / Discussions / Database
   

Database

 
GeneralRe: Problem while Inserting data in Postgres Partitioned table Pin
HalluSin8R31-Oct-10 18:21
HalluSin8R31-Oct-10 18:21 
QuestionBULK INSERT using oracle ODBC driver Pin
hatemtaleb29-Oct-10 2:39
hatemtaleb29-Oct-10 2:39 
AnswerRe: BULK INSERT using oracle ODBC driver Pin
Rajesh Anuhya29-Oct-10 3:06
professionalRajesh Anuhya29-Oct-10 3:06 
GeneralRe: BULK INSERT using oracle ODBC driver Pin
hatemtaleb29-Oct-10 6:22
hatemtaleb29-Oct-10 6:22 
GeneralRe: BULK INSERT using oracle ODBC driver Pin
Mycroft Holmes29-Oct-10 12:40
professionalMycroft Holmes29-Oct-10 12:40 
GeneralRe: BULK INSERT using oracle ODBC driver Pin
Rajesh Anuhya29-Oct-10 18:57
professionalRajesh Anuhya29-Oct-10 18:57 
AnswerRe: BULK INSERT using oracle ODBC driver Pin
Rajesh Anuhya29-Oct-10 18:51
professionalRajesh Anuhya29-Oct-10 18:51 
Questioninsert and update Pin
future383929-Oct-10 0:02
future383929-Oct-10 0:02 
Hi Guys,
I am writing code for an insert part. I would like to write an store procedure which do both insert and update of my table. Imean when user call SP and pass the parameter if it was regarding insert add data otherwise update them.
is it possible?

here is my code
USE [Hostel]
GO
/****** Object:  StoredProcedure [dbo].[SprocInsertUpdatePerson]    Script Date: 10/29/2010 20:45:42 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SprocInsertUpdatePerson]
(-- Definition of Storeprocedure's parameter
	@id int,	
	@fname nvarchar(50),
	@srname nvarchar(50),
	@gender nvarchar(15),
	@dob datetime,
	@transactionid int	
)
AS

	Declare @ReturnValue int
	if (@id IS NULL) --New Item
	Begin
	set identity_insert Person_prs off
		insert into Person_prs
		(
			id_prs,
			fname_prs,
			srname_prs,
			gender_prs,
			dob_prs,
			transactionid_prs
		)	
		values
		(
			@id,
			@fname ,
			@srname,
			@gender,
			@dob ,
			@transactionid			
		)
		
		Select @ReturnValue = Scope_Identity()
		
	End
	
	
	else
	
	Begin --Update Item
		Update Person_prs  		
		Set 
		--Id = @id,
		fname_prs = @fname,
		srname_prs = @srname,
		gender_prs = @gender,
		dob_prs = @dob,
		transactionid_prs = @transactionid
		where  id_prs = @id
		
		Select @ReturnValue = @id
	End
	
	
	IF (@@ERROR != 0)
	BEGIN
		RETURN -1
	END
	ELSE
	BEGIN
		RETURN @ReturnValue
	END


the problem is how to set the parameter for update or insert. in update I have to pass parameter to do search while in insert don't need it. however I should define my parameter.

does any one has idea,please?
AnswerRe: insert and update Pin
Rajesh Anuhya29-Oct-10 0:15
professionalRajesh Anuhya29-Oct-10 0:15 
GeneralRe: insert and update Pin
future383929-Oct-10 0:22
future383929-Oct-10 0:22 
AnswerRe: insert and update Pin
Mycroft Holmes29-Oct-10 0:35
professionalMycroft Holmes29-Oct-10 0:35 
GeneralRe: insert and update Pin
future383929-Oct-10 3:01
future383929-Oct-10 3:01 
GeneralRe: insert and update Pin
Mycroft Holmes29-Oct-10 12:38
professionalMycroft Holmes29-Oct-10 12:38 
AnswerRe: insert and update Pin
Rajesh Anuhya29-Oct-10 3:08
professionalRajesh Anuhya29-Oct-10 3:08 
GeneralRe: insert and update Pin
future383929-Oct-10 3:15
future383929-Oct-10 3:15 
GeneralRe: insert and update Pin
future383929-Oct-10 3:25
future383929-Oct-10 3:25 
Questionget the record identity from PostgreSQ/ Pin
Jassim Rahma28-Oct-10 4:57
Jassim Rahma28-Oct-10 4:57 
AnswerRe: get the record identity from PostgreSQ/ Pin
Chris Meech28-Oct-10 5:16
Chris Meech28-Oct-10 5:16 
AnswerRe: get the record identity from PostgreSQ/ Pin
David Skelly28-Oct-10 22:35
David Skelly28-Oct-10 22:35 
QuestionPivot? Pin
mark_w_28-Oct-10 3:08
mark_w_28-Oct-10 3:08 
AnswerRe: Pivot? Pin
Goutam Patra28-Oct-10 3:18
professionalGoutam Patra28-Oct-10 3:18 
GeneralRe: Pivot? Pin
mark_w_28-Oct-10 3:24
mark_w_28-Oct-10 3:24 
GeneralRe: Pivot? Pin
Goutam Patra28-Oct-10 3:35
professionalGoutam Patra28-Oct-10 3:35 
AnswerRe: Pivot? Pin
David Mujica28-Oct-10 4:19
David Mujica28-Oct-10 4:19 
GeneralRe: Pivot? Pin
mark_w_28-Oct-10 4:25
mark_w_28-Oct-10 4:25 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.