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)
 Simple fetching columns to variables

Author  Topic 

majkinetor
Yak Posting Veteran

55 Posts

Posted - 2006-03-17 : 06:56:25
I have table with 1 row and 5 columns. I want to work with some values there. Is there any qucik way to obtain those variables without cursor and without using multiple subsequent select statements that will return that single row.

Now I do like this:

declare @col3
declare @col5

set @col3 = (select col3 from ...)
set @col5 = (select col5 from ...)

or I can do with cursor.

But I want something that can be best described with this pseudocode:

select col1, col2, set @col3=col3, col4, set @col5=col5
from openXML(..)
with (col1 as ..., col2 as... )

This way I run only one select statement to fetch all variables and I don't use memory intensive cursors.
Be awrare that table contains only 1 row.

Also, I need to have complete query on XMLtable like the last one above since this is the way for me to check if all columns are of correct type (since @@error will be > 0 if something is wrong with types). SO I thought, If I already have select which will return everything, there must be some way to access this row in some way that is fast and not memory intensive since I have to call this procedure a lot.

thx


khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-03-17 : 07:50:50
[code]select @col1 = col1, @col2 = col2, @col3=col3, @col4 = col4, @col5 = col5
from yourtable
where ...[/code]



KH

Choice is an illusion, created between those with power, and those without.
Concordantly, while your first question may be the most pertinent, you may or may not realize it is also the most irrelevant

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-03-17 : 09:28:06
Note that if there are more than one values then the variables will have the last values

Madhivanan

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

majkinetor
Yak Posting Veteran

55 Posts

Posted - 2006-03-17 : 09:36:08
Thx people
Go to Top of Page
   

- Advertisement -