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

fetch multiple columns value in stored Procedure

Soniad
P: 66
Hello,


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 
Regards,
"D"
Feb 1 '09 #1
Share this Question
Share on Google+
3 Replies


Soniad
P: 66
Hello,


I used this logic, and its working,


Expand|Select|Wrap|Line Numbers
  1. Declare @Groupcounts varchar(8000),@chrSubGrpCharge  varchar(1)       
  2.  
  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

Regards,
"D"
Feb 1 '09 #2

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

-- CK
Feb 1 '09 #3

Soniad
P: 66
@ck9663
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.


Regards,
"D"
Feb 2 '09 #4

Post your reply

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