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
 passing entire row as a parameter

Author  Topic 

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-30 : 08:25:33
How to pass entier row to a function and receive in SQL, as in Oracle
we have %rowtype

eg. I found the oracle code which needs to be converted to sql
this I found in a procedure

v_price_row & v_product_row is tablename%rowtype variables
pos.master_margin_center is a cursor variable


v_price_row := get_price_row(pos.global_product_id,v_legal_entity,pos.master_margin_center,in_data_status);
v_product_row := get_product_row(pos.global_product_id, v_legal_entity, pos.master_margin_center, 'O');




-Neil

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-30 : 09:32:12
You're going to be better off if you don't ask for conversion, and just asked what the requirement is...

Ahh...but there's the rub...I don't think you know what's going on either...



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-30 : 09:48:43
I just asked, how we can pass & receive the entire table row in SQL Sproc.



-Neil
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-30 : 09:51:07
Pass all the columns as parameters



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-30 : 09:58:59
[code]
/*

CREATE TABLE #myTable99 (Col1 int, Col2 varchar(10), Col3 datetime)

CREATE PROCEDURE [dbo].[sprocname]
AS
@Col1 int
, @Col2 varchar(10)
, @Col3 datetime
, @out_Col1 int OUTPUT
, @out_Col2 varchar(10) OUTPUT
, @out_Col3 datetime OUTPUT
*/

DECLARE @out_Col1 int, @out_Col2 varchar(10), @out_Col3

EXEC SprocName
1 -- Col1 int
, 'xxx' -- Col2 varchar(10)
, '09/11/2001' -- Col3 datetime
, @out_Col1 OUTPUT
, @out_Col2 OUTPUT
, @out_Col3 OUTPUT
[/code]


Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

aakcse
Aged Yak Warrior

570 Posts

Posted - 2010-06-30 : 10:01:24
Ok, If I pass all the columns as a parameter, and would like to receive one entire row from a table, how can I do this in SQL

some thing like below( I google and found this at
http://www.developmentnow.com/g/113_2004_5_0_0_428011/What-is-the-eqivelant-for-the-RowType-of-oracle-in-T-SQL.htm

Now can I declare a table variable and assinge entire row returned by this function to it?




CREATE FUNCTION LargeOrderShippers ( @FreightParm money )
RETURNS @OrderShipperTab TABLE
(
ShipperID int,
ShipperName nvarchar(80),
OrderID int,
ShippedDate datetime,
Freight money
)
AS
BEGIN
INSERT @OrderShipperTab
SELECT S.ShipperID, S.CompanyName,
O.OrderID, O.ShippedDate, O.Freight
FROM Shippers AS S INNER JOIN Orders AS O
ON S.ShipperID = O.ShipVia
WHERE O.Freight > @FreightParm
RETURN
END



-Neil
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2010-06-30 : 10:07:56
From your link

quote:

Are you
attempting some sort of procedural row-by-row processing? If so, maybe there
is a set-based solution that avoids the need for this. Please describe your
requirements



But yes, you can define a table varibable..butr what do you want to return? You still have to do this explicitly...



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2010-06-30 : 11:14:28
Yes, basically the same answser that we gave you in this thread:
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=146617

In order to store the results of your fuction call in a variable you can do something like:
-- Create New Type
IF NOT EXISTS
(
SELECT *
FROM sys.types st
JOIN sys.schemas ss
ON st.schema_id = ss.schema_id
WHERE st.name = N'OrderShipperTableType'
AND ss.name = N'dbo'
)
CREATE TYPE dbo.OrderShipperTableType AS TABLE
(
ShipperID int,
ShipperName nvarchar(80),
OrderID int,
ShippedDate datetime,
Freight money
)
GO

-- Declare and User new type
DECLARE @MyTab dbo.OrderShipperTableType

-- Can insert all or jsut one row from the fucntion
INSERT @MyTab
SELECT TOP 1 * FROM dbo.LargeOrderShippers($100.00)

-- Insert stored procedure call here, passing @MyTab

--DROP TYPE dbo.MyTableType
It might be working looking up "table-valued parameters" in Books Online.
Go to Top of Page
   

- Advertisement -