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
 General SQL Server Forums
 New to SQL Server Programming
 sqlserver InOut parameter

Author  Topic 

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2008-11-13 : 05:55:26
Dear Friend,

In oracle there are In,out,InOut Parameter passing is available.In sqlserver In and Out is possible. Is there InOut parameter available in sqlserver? if means please let me know.

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2008-11-13 : 06:03:53
you mean in the stored procedures? the out parameter is used for this.

_______________________________________________
Causing trouble since 1980
Blog: http://weblogs.sqlteam.com/mladenp
Speed up SSMS development: www.ssmstoolspack.com <- version 1.1 out!
Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2008-11-13 : 06:20:27
thank you friend
Go to Top of Page

lionofdezert
Aged Yak Warrior

885 Posts

Posted - 2008-11-13 : 06:27:52
Only difference is INOut keyword, these is no such keyword used in sql server. Only OUTPUT keyword is used and also u need to mention IN keyword for IN parameter.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-13 : 06:31:45
All parameters in SQL Server are by default IN parameters.
You only need to specify OUT[PUT] if you want it to be OUTPUT parameter too.



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2008-11-13 : 23:54:00
hi, as per your advice i have done some sample.ths is my code:

CREATE PROCEDURE [dbo].[SP_GetEmpDetails](@name varchar(50) output,@Empsalary int output)
as
BEGIN
set @name =(select EmpID from EmpDetails where EmpName=@name)
set @Empsalary =(select salary from EmpDetails where EmpName=@name)
select @name,@Empsalary


END

here i used @name as in and out purpose.
@Empsalary as out parameter. when i execute it shows Empid as correct.but Empsalary as null. what could be the reason and please help me to solve this issue

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-14 : 00:49:56
how were you executing the sp?
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-14 : 02:09:03
Your first set statement replaces/overwrites value for @name parameter with ID for employee!
CREATE  PROCEDURE [dbo].[SP_GetEmpDetails](@name  varchar(50) output,@Empsalary int output)
as
BEGIN
set @name =(select EmpID from EmpDetails where EmpName=@name)
set @Empsalary =(select salary from EmpDetails where Empid=@name)
select @name,@Empsalary



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

sqllover
Constraint Violating Yak Guru

338 Posts

Posted - 2008-11-14 : 03:40:28
thanks friends.

could it be done using cursors? if means please show me some example please
Go to Top of Page

vinayakshukre
Starting Member

11 Posts

Posted - 2009-01-01 : 00:43:29
Thanks a ton. I was also looking for the same i.e. inout in ms sql server.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-01 : 13:04:38
quote:
Originally posted by sqllover

thanks friends.

could it be done using cursors? if means please show me some example please


yup it can be. but can i ask why you need cursor to return some value? cant a set based solution be enough?
Go to Top of Page

pankaj.todkar
Starting Member

1 Post

Posted - 2011-04-29 : 06:50:11
CREATE PROCEDURE [dbo].[SP_GetEmpDetails](@name varchar(50) output,@Empsalary int output)
as
BEGIN

set @Empsalary =(select salary from EmpDetails where EmpName=@name)
set @name =(select EmpID from EmpDetails where EmpName=@name)

select @name,@Empsalary


END


Highlighted lines exchanged can resolve Your Problem too..

Rgds,
Pankaj Todkar
Go to Top of Page

raghuveer125
Constraint Violating Yak Guru

285 Posts

Posted - 2011-04-29 : 08:01:19
See here is step by step explanation
http://www.simple-talk.com/sql/learn-sql-server/implementing-the-output-clause-in-sql-server-2008/

How in and out parameter works

Raghu' S
Go to Top of Page
   

- Advertisement -