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 2005 Forums
 Transact-SQL (2005)
 Simple Query

Author  Topic 

karthik
Starting Member

8 Posts

Posted - 2007-12-03 : 07:41:52
create PROCEDURE [dbo].[SPName]
(
@Field1 varchar(50) = NULL output,
@Field2 varchar(50) = NULL output,
)
AS
Select Field1,Field2,Field3 from table1 where PK=1


Above is the simple SP, Here i want to return fields to output parameter not as table. What is the best solution

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2007-12-03 : 07:44:17
quote:
Originally posted by karthik


create PROCEDURE [dbo].[SPName]
(
@Field1 varchar(50) = NULL output,
@Field2 varchar(50) = NULL output
)
AS
Select @Field1 = Field1, @Field2 = Field2 from table1
RETURN
GO


Above is the simple SP, Here i want to return fields to output parameter not as table. What is the best solution



Harsh Athalye
India.
"The IMPOSSIBLE is often UNTRIED"
Go to Top of Page

ayamas
Aged Yak Warrior

552 Posts

Posted - 2007-12-03 : 08:03:09
quote:
Originally posted by karthik


create PROCEDURE [dbo].[SPName]
(
@Field1 varchar(50) = NULL output,
@Field2 varchar(50) = NULL output,
)
AS
Select Field1,Field2 from table1


Above is the simple SP, Here i want to return fields to output parameter not as table. What is the best solution



But there is no where condition in the select statement?
How will the parameters return single value if the select statement returns multiple records?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-03 : 08:04:17
quote:
Originally posted by ayamas

quote:
Originally posted by karthik


create PROCEDURE [dbo].[SPName]
(
@Field1 varchar(50) = NULL output,
@Field2 varchar(50) = NULL output,
)
AS
Select Field1,Field2 from table1


Above is the simple SP, Here i want to return fields to output parameter not as table. What is the best solution



But there is no where condition in the select statement?
How will the parameters return single value if the select statement returns more than multiple records?


It would just retunr the last value assigned


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

karthik
Starting Member

8 Posts

Posted - 2007-12-03 : 08:07:12
I missed one field and where clause. Look at My first Post

The query is
Select Field1,Field2,Field3 from table1 where PK=1


Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-03 : 08:12:06
quote:
Originally posted by karthik


I missed one field

The query is
Select Field1,Field2,Field3 from table1





Well. Do you want to return single value for each parameter or multiple values?

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-03 : 08:34:57
Well. You edited the reply but didnt answer to my question

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

karthik
Starting Member

8 Posts

Posted - 2007-12-03 : 08:49:44
quote:
Originally posted by madhivanan

Well. You edited the reply but didnt answer to my question

Madhivanan

Failing to plan is Planning to fail



Single Value
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2007-12-03 : 08:53:45
Try

create PROCEDURE [dbo].[SPName]
(
@param1 varchar(50) = NULL output,
@param2 varchar(50) = NULL output,
@param3 varchar(50) = NULL output
)
AS
Select @param1 = param1, @param2 = param2, @param3 = param3 from table1 where where PK=1
RETURN
GO


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -