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 2000 Forums
 Transact-SQL (2000)
 %rowtype problem

Author  Topic 

nsrao_1975
Starting Member

13 Posts

Posted - 2004-02-17 : 01:29:57
hi,

i want to fetch the entire row into a variable and refer each column for further manipulation as we do in oracle like under

currow emp%rowtype

and later

IF emp.deptid <> 'Accounts' ...

but in sqlserver i could not find any similar datatype to fetch the entire row into a variable..

can any guru helpmeout here...?

Thanks in advance

VyasKN
SQL Server MVP &amp; SQLTeam MVY

313 Posts

Posted - 2004-02-17 : 05:51:47
No such datatype in SQL Server. You could get all the columns of a row into variables though, as shown below:

DECLARE @Col1 int, @Col2 int
SELECT @Col1 = Col1, @Col2 = Col2
FROM YourTable
WHERE Coln = 12345

--
HTH,
Vyas
http://vyaskn.tripod.com
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2004-02-17 : 06:30:58
Why would you want to do that?
currow implies cursor processing I think

You can create a table variable or temp table and insert a row from the table into it.
select * into #a from tbl where pk = @myrow

But why not just refer to the row in the table using the PK intead?
IF emp.deptid <> 'Accounts' ...
becomes
if not exists (select * from emp where pk = @myrow and emp.deptid <> 'Accounts')


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -