Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

t-sql help - stored procedure call anther stored procedure

Posted on 2013-02-05
12
Medium Priority
?
365 Views
Last Modified: 2013-02-06
I need help on #2 and #3:

1) select data from a table, stored the STD_ID in the temp table.

2) need to execute anther stored procedure 'GET_STD_INFO ' pass in the STD_ID, it will return  columns included the following:
STD_ID, STD_NAME, ACTIVE_IND AND CLASSES_TOTAL, etc...

3) need to update the temp table with the return columns of STD_ID, STD_NAME, ACTIVE_IND AND CLASSES_TOTAL



DECLARE @TMP_TEST table
(
      STD_ID                  INT,
      STD_NAME            VARCHAR(50),
      ACTIVE_IND            CHAR(1),
      CLASSES_TOTAL            INT
      )



INSERT @TMP_TEST
      (
      STD_ID
      )
SELECT  DISTINCT
      TOP 1 STD_ID
FROM STUDENT_TB
ORDER BY ACTIVE_YEAR


what is the best way to do this?

thank you,

I am running in  MS SQL server 2010.
0
Comment
Question by:jfreeman2010
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
12 Comments
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 38857173
seem like an assignment to me ?
0
 

Author Comment

by:jfreeman2010
ID: 38857241
Its better way to do this beside to DECLARE CURSOR on #2?
0
 
LVL 75

Expert Comment

by:Aneesh Retnakaran
ID: 38857250
yes, you can do that withou a cursor. but we are not suppose to provide answers to the assignments
0
How Blockchain Is Impacting Every Industry

Blockchain expert Alex Tapscott talks to Acronis VP Frank Jablonski about this revolutionary technology and how it's making inroads into other industries and facets of everyday life.

 

Author Comment

by:jfreeman2010
ID: 38857276
Hi aneeshattingal,

I don't understand what you mean assignments????
0
 

Author Comment

by:jfreeman2010
ID: 38857476
this is NOT a student assignment, the example above just to make it easy to understand ( at lease if for me), and it part of what I need to do for work.
0
 
LVL 75

Accepted Solution

by:
Aneesh Retnakaran earned 2000 total points
ID: 38857487
the way you described the question seems suspecious. thats why I asked you


declare @rows int , @stdid int 


DECLARE @TMP_TEST table
(     i int identity , 
      STD_ID                  INT,
      STD_NAME            VARCHAR(50),
      ACTIVE_IND            CHAR(1),
      CLASSES_TOTAL            INT
      ) 

CREATE TABLE #tmp
(    
      STD_ID                  INT,
      STD_NAME            VARCHAR(50),
      ACTIVE_IND            CHAR(1),
      CLASSES_TOTAL            INT
      ) 

INSERT @TMP_TEST
      (
      STD_ID
      )
SELECT  DISTINCT
      TOP 1 STD_ID
FROM STUDENT_TB 

select @rows = @@ROWCOUNT

while @rows > 0 
BEGIN
	SELECT @stdid =  std_id 
	from @TMP_TEST 
	where i = @rows 
	
	SELECT @rows = @rows - 1 
	insert into #tmp
	exec GET_STD_INFO @stdid 
END 

update t
set std_name = d.std_name, 
    active_ind = d.active_ind,
    Classes_total = d.classes_total
FROM @TMP_TEST t
inner join #temp d on t.STD_ID = d.std_id

Open in new window

0
 

Author Comment

by:jfreeman2010
ID: 38857553
Hi aneeshattingal,

THANK YOU FOR HELP!!!  I think will just make it easy to ask the question.

I have 2 questions :  

1) can the #tmp be @tmp as table variable ?
2) what happen is the get_std_info return more columns then the #tmp/@tmp table list columns?  do I need to list all the columns return from get_std_info in the #tmp/@tmp?



Thank you very much for help.
0
 

Expert Comment

by:callmeraghavendra
ID: 38859767
Hi,

yes the #temp table can be used as @temp variable and you might need to tweak the get_std_info to return only the columns that you like to insert into the Temp table.
0
 

Author Comment

by:jfreeman2010
ID: 38859787
ok, I will try.  thank you very much for your helping...
0
 
LVL 75

Assisted Solution

by:Aneesh Retnakaran
Aneesh Retnakaran earned 2000 total points
ID: 38860053
>what happen is the get_std_info return more columns then the #tmp/@tmp table list columns?  do I need to list all the columns return from get_std_info in the #tmp/@tmp?
I would take the logic of get_std_info and join the @TMP_TEST  table, rather than loop thru each id and call the sp, but it depends on the complexity of your stored procedure; Other option will be conver get_std_info  to a function and join with @TMP_TEST  table.

Aneesh
0
 

Author Comment

by:jfreeman2010
ID: 38860119
YES Aneesh, that is what I am trying to do, and the logic is very  complex and I am still working.... thank you for your suggestion.
0
 

Author Closing Comment

by:jfreeman2010
ID: 38860129
thank you for all your help!!!
0

Featured Post

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question