473,396 Members | 1,712 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

fetch multiple columns value in stored Procedure

Soniad
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
3 27479
Soniad
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
2,878 Expert 2GB
Be careful with using select in assigning values to variable. Read this

-- CK
Feb 1 '09 #3
Soniad
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

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

Similar topics

1
by: Agoston Bejo | last post by:
The problem is as follows: I have a stored proc. that returns a types.ref_cursor (where types.ref_cursor is defined as 'ref cursor'): PROCEDURE P(c OUT TYPES.ref_cursor); The returned cursor has...
3
by: JB | last post by:
To anyone that is able to help.... What I am trying to do is this. I have two tables (Orders, and OrderDetails), and my question is on the order details. I would like to set up a stored...
3
by: Gaz | last post by:
I have a table which has 10 columns which make up the secondary key. 1 or more of these columns can be set but the remaining columns in the secondary key will be null. For example : id k1 k2...
1
by: Andrew | last post by:
Hey all, I am very new to ASP.Net (and .Net in general), but that isn't stopping the boss from wanting to begin new projects in it. This latest project has me kinda stumped and after a couple...
6
by: James Radke | last post by:
Hello, I have a multithreaded windows NT service application (vb.net 2003) that I am working on (my first one), which reads a message queue and creates multiple threads to perform the processing...
2
by: Joe Campbell | last post by:
I have a DBA that wrote a stored procedure that does a SELECT from a particluar SQL Server table. Within that stored procedure he links over to grab a column from another database table. I need to...
4
by: db2admin | last post by:
hi, For the following SQL and plan ============================================================== SELECT Q1.PLCY_KY, Q1.PLCY_TRM_EFCTV_DT, Q1.ACNTG_BGN_DT, CASE WHEN ((Q1.PLCY_SRC_CD = '02')...
3
by: Otto Carl Marte | last post by:
Hi, As I understand it, Declared Global Temporary Tables (DGTTs) have a scope that is session/connection based. Using the same connection, I have discovered that if I declare a DGTT in one...
43
by: bonneylake | last post by:
Hey Everyone, Well this is my first time asking a question on here so please forgive me if i post my question in the wrong section. What i am trying to do is upload multiple files like gmail...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.