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

x
?
Solved

running default value for a stored procedure in sql server 2008

Posted on 2011-02-10
2
Medium Priority
?
395 Views
Last Modified: 2012-05-11
I want to run all for the third parameter ,@divisionID but it is erroring out:
USE [Database]
GO

DECLARE      @return_value int

EXEC      @return_value = [dbo].[usp_Program_Costing]
            @Staff_ID = N'ALL',
            @Terms = '2011F',
            @divisionID ='  '

What do I need to use?

Thanks,
Nigluc

USE [database]
GO
/****** Object:  StoredProcedure [dbo].[usp_Program_Costing]    Script Date: 02/10/2011 21:40:13 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER OFF
GO


ALTER                     PROCEDURE [dbo].[usp_Program_Costing]

(@Staff_ID nvarchar(4000),
@Terms varchar(500),
@divisionID nvarchar(100))

 
AS


create table #SWF

(      Staff_ID nvarchar (7) NOT NULL ,
        divisionID nvarchar (2)  NOT NULL ,
      Term nvarchar (5) NOT NULL ,
      Course nvarchar (10)  NOT NULL ,
      SWF_Section_Size int NULL  ,
      Start_Date datetime NOT NULL ,
      End_Date datetime NOT NULL ,
        Sect nvarchar (2) NULL ,
        Ckey int NOT NULL,
        Assigned_Teaching_Hours int NULL,
        Preparation_Attributed_Hours money Null,
        Evaluation nvarchar (2) NULL,
        Evaluation_Factor money NULL,
        Evaluation_Attributed_Hours money NULL,
        Section_Total_Hours money NULL,
        WeeklyTCH  Float Null,
        Enrol_Tot int NULL,
        MyCount int NULL,
        Program nvarchar (4) NULL,
        ProgramACAD nvarchar (4) NULL,
        TCW int NULL,
        Revision int Null,
        Complementary_Hours_Assigned money Null,
        EmpName nvarchar (30) NULL,

       
       
)

create table #SWF_Header_HKey2
( Term2 nvarchar(5)Not Null,
  divisionID2 nvarchar (5) Not Null,
  Staff_Id2 nvarchar (7) Not Null,
  Seq2 int Not Null,
  HKey2 int Not Null)

create table #SWF_Header_Course2
(divisionID3 varchar(2) Not Null,
 HKey3 Int Not Null,
 Ckey3 Int Not Null)
     
IF @Staff_ID='ALL'
BEGIN


INSERT #SWF_HEADER_HKey2(Term2, divisionID2, Staff_Id2, Seq2,HKey2)
Select Term,
       divisionID,
       Staff_Id,
       Seq,
       HKey
from SWF_Header SWFH
INNER JOIN iter_charlist_to_table(@Terms, DEFAULT) s ON  SWFH.TERM = s.nstr
INNER JOIN iter_charlist_to_table(@divisionID, DEFAULT)s3 ON  SWFH.divisionID = s3.nstr  

Insert #SWF_Header_Course2(divisionID3,HKey3, Ckey3)
Select divisionID
       ,Hkey
       ,Ckey
from SWF_Header_Course SWF_HC
LEFT OUTER JOIN  #SWF_Header_HKey2 SWF_HH on SWF_HC.HKey = SWF_HH.HKey2

INSERT #SWF (Staff_ID,divisionID,Term,Course,Start_Date,End_Date/*,SWF_Section_Size*/,Ckey,Assigned_Teaching_Hours,Preparation_Attributed_Hours,Evaluation,Evaluation_Factor,Evaluation_Attributed_Hours,Section_Total_Hours,Revision,Complementary_Hours_Assigned )
Select DISTINCT
Staff_ID
,divisionID
,Term      
,Course
,Start_Date
,End_Date
--,SWF_Section_Size
,Ckey
,Assigned_Teaching_Hours
,Preparation_Attributed_Hours
,Evaluation
,Evaluation_Factor
,Evaluation_Attributed_Hours
,Section_Total_Hours
,Revision
,Complementary_Hours_Assigned

FROM   dbo.SWF_Section SWF(NOLOCK)
LEFT OUTER JOIN #SWF_Header_Course2 SWF_HC (NOLOCK)ON SWF_HC.CKey3 =SWF.cKey
INNER  JOIN iter_charlist_to_table(@Terms, DEFAULT) d ON  SWF.TERM = d.nstr
INNER JOIN iter_charlist_to_table(@divisionID, DEFAULT)s3 ON  SWF.divisionID = s3.nstr  
WHERE  (Preparation IS NOT NULL
AND Preparation_Attributed_Hours IS NOT NULL
AND Evaluation IS NOT NULL
AND Evaluation_Factor IS NOT NULL
AND Evaluation_Attributed_Hours IS NOT NULL)
ORDER BY Course


UPDATE #SWF
Set Sect = Sect.Sect
FROM #SWF,
SWF_Section AS Sect (NOLOCK)
WHERE #SWF.Ckey=Sect.cKey
--#SWF.divisionID =Sect.divisionID
--and   #SWF.Term = Sect.Term
--and   #SWF.Course = Sect.Course

UPDATE #SWF
Set SWF_Section_Size = Sect.SWF_Section_Size
FROM #SWF,
SWF_Section AS Sect (NOLOCK)
WHERE #SWF.Ckey=Sect.cKey
--#SWF.divisionID =Sect.divisionID
--and   #SWF.Term = Sect.Term
--and   #SWF.Course = Sect.Course
--AND   #SWF.Start_Date=Sect.Start_Date
--AND   #SWF.End_Date=Sect.End_Date
--AND   #SWF.Staff_ID = Sect.Staff_ID

/* weekly tch */
UPDATE #SWF
Set WeeklyTCH = Course.Credit_Value
FROM #SWF
LEFT OUTER JOIN Course AS  Course (NOLOCK)on #SWF.divisionID =Course.divisionID
and   #SWF.Term = Course.Term
and   #SWF.Course = Course.Course

UPDATE #SWF
Set Enrol_Tot = Enrol.ENRL_TOT
FROM #SWF
LEFT OUTER JOIN tblActualEnrolment AS Enrol (NOLOCK) ON #SWF.Term=Enrol.Term
where #SWF.Course=(Enrol.SUBJECT+Enrol.CATALOG_NBR)
and #SWF.Sect=Enrol.CLASS_SECTION



/* will be changed to reflect the dbo.PS_CLASS_TBL */
UPDATE #SWF
Set MyCount= Enrol.MyCount
FROM #SWF
LEFT OUTER JOIN tblActualEnrolment AS Enrol (NOLOCK) ON #SWF.Term=Enrol.Term
where #SWF.Course=(Enrol.SUBJECT+Enrol.CATALOG_NBR)
and #SWF.Sect=Enrol.CLASS_SECTION


/*Program*/
UPDATE #SWF
Set Program=LoadDet.Program
FROM #SWF
LEFT OUTER JOIN  dbo.Loadings_Detail AS LoadDet (NOLOCK) ON #SWF.DivisionID=LoadDet.DivisionID
where #SWF.Term = LoadDet.Term
and   #SWF.Course = LoadDet.Course
and   #SWF.Sect = LoadDet.Sect

UPDATE #SWF
Set ProgramACAD = PAO.ACAD_Org
FROM #SWF
LEFT OUTER JOIN dbo.ProgramACAD_Org AS PAO (NOLOCK) ON PAO.Program = #SWF.Program


UPDATE #SWF
Set TCW = swfh.Prev_TCW
FROM #SWF
LEFT OUTER JOIN dbo.SWF_Totals AS swfh (NOLOCK) ON #SWF.DivisionID=swfh.DivisionID
where #SWF.Term = swfh.Term
and   #SWF.Staff_ID = swfh.Staff_ID

UPDATE #SWF
Set #SWF.EmpName= Staff.Surname + ',' + Staff.First_Name
from #SWF
LEFT OUTER JOIN dbo.Staff AS Staff ON Staff.[ID] =  #SWF.Staff_ID

Select * from #SWF
END




0
Comment
Question by:Lucia
[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
2 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 34869051
Can you explain little more? What error are you getting now?
0
 

Author Closing Comment

by:Lucia
ID: 34875932
It has been awhile since I have run stored procedures.  I wanted to run for all in the division category.  

I managed to do it.

Thank you for responding to my post.

Niglluc
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
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.

722 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