| 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 sqlthis I found in a procedure v_price_row & v_product_row is tablename%rowtype variablespos.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 |
|
|
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 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
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_Col3EXEC SprocName 1 -- Col1 int , 'xxx' -- Col2 varchar(10) , '09/11/2001' -- Col3 datetime , @out_Col1 OUTPUT , @out_Col2 OUTPUT , @out_Col3 OUTPUT[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
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 SQLsome 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 )ASBEGIN 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 RETURNEND -Neil |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2010-06-30 : 10:07:56
|
From your linkquote: Are youattempting some sort of procedural row-by-row processing? If so, maybe thereis a set-based solution that avoids the need for this. Please describe yourrequirements
But yes, you can define a table varibable..butr what do you want to return? You still have to do this explicitly...Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxAdd yourself!http://www.frappr.com/sqlteam |
 |
|
|
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=146617In order to store the results of your fuction call in a variable you can do something like:-- Create New TypeIF 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 typeDECLARE @MyTab dbo.OrderShipperTableType-- Can insert all or jsut one row from the fucntionINSERT @MyTabSELECT 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. |
 |
|
|
|