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

x
?
Solved

MS SQL -2005 Procedure

Posted on 2007-04-11
2
Medium Priority
?
160 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 1000 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

Learn Veeam advantages over legacy backup

Every day, more and more legacy backup customers switch to Veeam. Technologies designed for the client-server era cannot restore any IT service running in the hybrid cloud within seconds. Learn top Veeam advantages over legacy backup and get Veeam for the price of your renewal

Question has a verified solution.

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

When writing XML code a very difficult part is when we like to remove all the elements or attributes from the XML that have no data. I would like to share a set of recursive MSSQL stored procedures that I have made to remove those elements from …
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …

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