fetch multiple columns value in stored Procedure

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Soniad
    New Member
    • Jan 2009
    • 66

    fetch multiple columns value in stored Procedure

    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.


    Code:
     SET NOCOUNT ON    
     Set @Grpdtls = CURSOR FAST_FORWARD        
     for         
     select vchgrouprec_id,chrGroup_Charge from mllgroup_details where intgroup_id= @lastgrpid        
     Open @Grpdtls        
     Fetch from @Grpdtls  into @Groupcounts,@chrSubGrpCharge        
     CLOSE @Grpdtls        
     DEALLOCATE @Grpdtls
    Regards,
    "D"
  • Soniad
    New Member
    • Jan 2009
    • 66

    #2
    fetch multiple columns value in stored Procedure

    Hello,


    I used this logic, and its working,


    Code:
    Declare @Groupcounts varchar(8000),@chrSubGrpCharge  varchar(1)       
    
    select @Groupcounts =vchgrouprec_id,@chrSubGrpCharge=chrGroup_Charge 
    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"

    Comment

    • ck9663
      Recognized Expert Specialist
      • Jun 2007
      • 2878

      #3
      Be careful with using select in assigning values to variable. Read this

      -- CK

      Comment

      • Soniad
        New Member
        • Jan 2009
        • 66

        #4
        fetch multiple columns value in stored Procedure

        Originally posted by ck9663
        Be careful with using select in assigning values to variable. Read this

        -- CK
        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"

        Comment

        Working...