Solved

MS SQL -2005 Procedure

Posted on 2007-04-11
2
142 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
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

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

In this article I will describe the Backup & Restore method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

747 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

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now