Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2003-11-20 : 08:05:44
|
| Gary writes "I am not strong with Stored Procedures and have one that I could use your assistance with, if you have time. I need to add the following table / field to the below stored procedure, and am uncertain where to add it. I am merely attempting to add a field to a report from the table. The table is Proof Job Type and the field is ProofCode. I believe that it has to be declared after the SELECT statement as: dbo.[Proof Job Type].ProofCode. Another question, is it possible to change a sp to a view? If so, how?Thanks,Gary Alter PROCEDURE billm.spBMCoverSchedule ASSELECT dbo.BookAll.JobNum, dbo.[Cover Print Process].CvrPrntProcessID, dbo.[Cover Print Process].CvrPrntProcess, dbo.BookAll.DateIn, dbo.[Scheduling - AD].dtPrintCvr2, dbo.[Scheduling - AD].dtPrintTxt2, dbo.[Scheduling - AD].TxtPrfStatus, dbo.[Scheduling - AD].CvrPrfStatus, dbo.BookAll.Author, dbo.Publisher.PublisherCode, dbo.[Binding Style].BindStyleAbbr, dbo.BookAll.TotalWidth, dbo.BookAll.AllCovers + dbo.BookAll.ExtraCvrs AS Quantity, dbo.[Cover Colors].CvrColor, dbo.[Scheduling - AD].dtBNBInvRec, dbo.[Scheduling - AD].dtBound, dbo.[Scheduling - AD].dtShipped, dbo.[Scheduling - AD].dtBound2, dbo.[Scheduling - AD].BNBDelivery, dbo.[Scheduling-LoadedDates].PrintCoverDue, Hold, HotJob,'JobDueDate' =CASEWHEN [Hold] = 1 THEN '9/9/99'WHEN ([DaysOnHold] Is Not Null AND [CustomerDelay] = 1 And [Take Off Hold] = 1) THEN (dbo.BoundBook.BoundBook + [DaysOnHold])ELSE (dbo.BoundBook.BoundBook)END,'CoverStatus' = CASEWHEN [CvrPrfStatus] = '28' THEN 'RTP, Needs Plates'ELSE 'RTP'END,'Text Status' = CASEWHEN [dtPrintTxt2] is not null THEN 'Text Printed'When [dtPrintTxt2] is null and [TxtPrfStatus] = '12' Then 'RTP'ELSE 'Not RTP'ENDFROM dbo.BookAll INNER JOINdbo.[Scheduling - AD] ON dbo.BookAll.JobNum = dbo.[Scheduling - AD].JobNum INNER JOINdbo.[Job - ED] ON dbo.BookAll.JobNum = dbo.[Job - ED].JobNum INNER JOINdbo.Publisher ON dbo.BookAll.PublisherID = dbo.Publisher.PublisherId INNER JOINdbo.[Cover Print Process] ON dbo.BookAll.CvrPrntProcessID = dbo.[Cover Print Process].CvrPrntProcessIDLEFT OUTER JOINdbo.[Scheduling-LoadedDates] ON dbo.BookAll.JobNum = dbo.[Scheduling-LoadedDates].JobNum LEFTOUTER JOINdbo.BoundBook ON dbo.BookAll.JobNum = dbo.BoundBook.JobNum LEFT OUTER JOINdbo.[Hot Jobs] ON dbo.BookAll.JobNum = dbo.[Hot Jobs].JobNum LEFT OUTER JOINdbo.[Cover Colors] ON dbo.BookAll.CvrColorID = dbo.[Cover Colors].CvrColorID LEFT OUTERJOINdbo.[Binding Style] ON dbo.BookAll.BindStyleID = dbo.[Binding Style].BindStyleID LEFTOUTER JOINdbo.tblHoldJobs ON dbo.BookAll.JobNum = dbo.tblHoldJobs.JobNumberWHERE (dbo.[Scheduling - AD].dtBNBInvRec IS NULL) AND (dbo.[Scheduling - AD].dtBound IS NULL) AND (dbo.[Scheduling - AD].dtShipped IS NULL) AND (dbo.[Scheduling - AD].dtBound2 IS NULL) AND (dbo.[Scheduling - AD].BNBDelivery IS NULL) AND (dbo.BookAll.DateIn > CONVERT(DATETIME, '2002-12-31 00:00:00', 102)) AND (dbo.[Scheduling - AD].dtPrintCvr2 IS NULL) AND (dbo.[Cover Print Process].CvrPrntProcessID = 1 ORdbo.[Cover Print Process].CvrPrntProcessID = 2 ORdbo.[Cover Print Process].CvrPrntProcessID = 3) AND (dbo.[Scheduling - AD].CvrPrfStatus = 12 ORdbo.[Scheduling - AD].CvrPrfStatus = 20 ORdbo.[Scheduling - AD].CvrPrfStatus = 26 ORdbo.[Scheduling - AD].CvrPrfStatus = 28)AND dbo.BookAll.PODScanOnly is null " |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2003-11-20 : 12:55:07
|
| Why not build your query in Query Analyzer first? Then once it works correctly, you move it into a stored procedure. But yes columns go in the SELECT part, right before the FROM clause or INTO clause if you have one. I think that you need to do some reading on views and stored procedures as they are quite different. Looking at your query now though, yes this can be moved into a view. But what is the purpose of your stored procedure?Tara |
 |
|
|
|
|
|
|
|