Solved

MS SQL -2005 Procedure

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

Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to check data in sql table 11 47
SQL Trigger or Function that updates table with old values 5 42
Restrict result set 1 39
Help Required 2 32
by Mark Wills PIVOT is a great facility and solves many an EAV (Entity - Attribute - Value) type transformation where we need the information held as data within a column to become columns in their own right. Now, in some cases that is relatively…
Introduction: When running hybrid database environments, you often need to query some data from a remote db of any type, while being connected to your MS SQL Server database. Problems start when you try to combine that with some "user input" pass…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

773 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