By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,967 Members | 1,324 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,967 IT Pros & Developers. It's quick & easy.

fetch multiple columns value in stored Procedure

P: 66

In stored procedure, i am using query that fetches 2 columns record but single row. i have used cursor to fetch single record.
is there any way to fetch the record and put it in variable declared without using cursor , or any syntax .
As cursor is better to fetch multiple records, but here record fetched is single row record, but the problem i am facing is how to put this value in variable. if there was a single column then it is easy to put record directly in variable. but how to deal with multiple columns in select query.

Expand|Select|Wrap|Line Numbers
  1.  SET NOCOUNT ON    
  2.  Set @Grpdtls = CURSOR FAST_FORWARD        
  3.  for         
  4.  select vchgrouprec_id,chrGroup_Charge from mllgroup_details where intgroup_id= @lastgrpid        
  5.  Open @Grpdtls        
  6.  Fetch from @Grpdtls  into @Groupcounts,@chrSubGrpCharge        
  7.  CLOSE @Grpdtls        
  8.  DEALLOCATE @Grpdtls 
Feb 1 '09 #1
Share this Question
Share on Google+
3 Replies

P: 66

I used this logic, and its working,

Expand|Select|Wrap|Line Numbers
  1. Declare @Groupcounts varchar(8000),@chrSubGrpCharge  varchar(1)       
  3. select @Groupcounts =vchgrouprec_id,@chrSubGrpCharge=chrGroup_Charge 
  4. from mllgroup_details where intgroup_id= @lastgrpid  
I think its better to use such way, cursor is used to go through records row by row if there are multiple records

Feb 1 '09 #2

Expert 2.5K+
P: 2,878
Be careful with using select in assigning values to variable. Read this

-- CK
Feb 1 '09 #3

P: 66
Thank you for such nice information, i was unaware of this.this information helped me in using proper SET and SELECT statements and T- SQL statements.

Feb 2 '09 #4

Post your reply

Sign in to post your reply or Sign up for a free account.