Solved

MS SQL -2005 Procedure

Posted on 2007-04-11
2
153 Views
Last Modified: 2010-03-19
I am using MS SQL-2005, & created the following mentioned procedure which is working properly
Use DLI_DB
SELECT
      File_job=left(z.file_job,5),
      z.transporter,
      TransportationCost=Sum(Z.transportationcost),
      LocalTransportation=sum(z.localtransportcost),
      Commission=sum(z.commission),
      BorderExp=sum(z.TaxPaid),
      Extrapayment=sum(extrapayment),
      CDDeductFromTransporter=sum(z.CDDeductFromTransporter),
      CDWaiveToTransporter=sum(z.CDWaiveToTransporter),
      DeductionFromTransporter=sum(z.DeductionFromTransporter),
      Debit=isnull(z.debit,0),
      Dues=sum(z.Dues),
      Balance=(sum(z.localtransportcost)+sum(z.TransportationCost)+sum(extrapayment)+sum(z.Com
mission)+sum(z.taxpaid)+sum(z.CDWaiveToTransporter)
      (sum(z.CDDeductFromTransporter)+sum(z.DeductionFromTransporter)),
      DateOut=count(b.date_out),
      DateIn=count(b.date_in)
FROM cargodetailcontainertransportdet z join cargodetailcontainer b on b.sn=z.sn
WHERE z.TRANSPORTER='Tayaba Trading & Logistic Company'
group by left(z.file_job,5),
z.debit, z.transporter

Problem
-----------
When I am converting above statement after adding following line in procedure and running from front end it is showing error.
Create Procedure [dbo].[AT_RptTransporterPaymentSummary] (@Transporter as varchar(100)) as

Is there any need to define procedure with database name or where I am doing mistake please help.
Rgds.
Mehram

0
Comment
Question by:Mehram
[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 39

Accepted Solution

by:
appari earned 500 total points
ID: 18887839
within procedures you cannot use use statement,
try removing
use DLI_DB
0
 

Author Comment

by:Mehram
ID: 18887872
YES I HAVE REMOVED IT.
I THINK PROBLEM IS THAT:
I AM USING TWO STATEMENT IN ONE PROCEDURE THE FIRST STATEMENT IS CREATING TEMP2 TABLE AND IN SECOND STATEMENT I AM JOINING TEMP2 TABLE AND INSERTING DATA INTO THIS.
PRODCEDURE:
ALTER Procedure [dbo].[AT_RptTransporterPaymentSummary] (@Transporter as varchar(100)) as

if object_id('temp2') is not null Drop Table Temp2

begin
SELECT  
      File_job=left(z.file_job,5),
      z.transporter,
      TransportationCost=Sum(Z.transportationcost),
      LocalTransportation=sum(z.localtransportcost),
      Commission=sum(z.commission),
      BorderExp=sum(z.TaxPaid),
      Extrapayment=sum(extrapayment),
      CDDeductFromTransporter=sum(z.CDDeductFromTransporter),
      CDWaiveToTransporter=sum(z.CDWaiveToTransporter),
      DeductionFromTransporter=sum(z.DeductionFromTransporter),
      Debit=isnull(z.debit,0),
      Dues=sum(z.Dues),
Balance=(sum(z.localtransportcost)+sum(z.TransportationCost)+sum(extrapayment)+sum(z.Commission)+sum(z.taxpaid)+sum(z.CDWaiveToTransporter)
)-(sum(z.CDDeductFromTransporter)+sum(z.DeductionFromTransporter)),
      DateOut=count(b.date_out),
      DateIn=count(b.date_in)
into temp2
FROM cargodetailcontainertransportdet z join cargodetailcontainer b on b.sn=z.sn
WHERE z.TRANSPORTER=@transporter
group by left(z.file_job,5), z.debit, z.transporter
end


Begin
update a
set a.debit=x.amount
from
(select headsub,Amount=sum(amount) from CargoDetailVendorPayment where headsub=@transporter and vd='0' group by headsub)x
join temp2 a on a.transporter=x.headsub
end

SQL execute error:
Msg 207, Level 16, State 3, Procedure AT_RptTransporterPaymentSummary, Line 55
Invalid column name 'transporter'.
Msg 207, Level 16, State 1, Procedure AT_RptTransporterPaymentSummary, Line 55
Invalid column name 'debit'.

0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

739 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