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.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 HOW TO USE OUTER JOIN

Author  Topic 

avijit111@gmail.com
Yak Posting Veteran

55 Posts

Posted - 2009-06-22 : 08:22:46
--MAINGATE_RM 'MEHTASCL','RNV',1,'2009/01/01','2009/01/24'
ALTER PROCEDURE MAINGATE_RM
(
@company_no glcompany,
@location_no gllocn,
@lang_id int,
@date_from datetime,
@date_to datetime
)
as

declare @today datetime, @HEADING varchar(60)

select @today = @date_to
begin

create table #MAINGATE_RM
(
sl_no int,
company GLCOMPANY,
location GLLOCN,
unloading_no varchar(18),
entry_no varchar(3),
material varchar(60),
ul_po_no varchar(18),
ul_date_time varchar(25),
truck varchar(15),
ven_name varchar(100),
mg_entry_check_by varchar(20),
mg_entry_date_time varchar(25),
mg_entry_po varchar(18),
gross_date_time varchar(25),
gross_time_po varchar(18),
tare_date_time varchar(25),
tare_time_po varchar(18),
mg_exit_date_time varchar(25),
mg_exit_po varchar(18),
net_weight numeric(9),
puc varchar(10),
vendor_code cmn_cust_ven_code
)

SELECT @heading = 'MAINGATE REPORT'

insert into #MAINGATE_RM(company,location ,unloading_no,entry_no,material,ul_po_no,ul_date_time,
truck,ven_name,mg_entry_check_by,mg_entry_date_time, mg_entry_po,gross_date_time,gross_time_po,tare_date_time,
tare_time_po,mg_exit_date_time,mg_exit_po,net_weight,puc,vendor_code )

select a.company,a.location,a.unloading_no,a.entry_no,a.material,a.ul_po_no,CONVERT(DATETIME,a.ul_date_time,108),a.truck,
a.ven_name,a.mg_entry_check_by,CONVERT(DATETIME,a.mg_entry_date_time,103),a.mg_entry_po,
CONVERT(DATETIME,a.gross_date_time,103),a.gross_time_po,CONVERT(DATETIME,a.tare_date_time,103),
a.tare_time_po,CONVERT(DATETIME,a.mg_exit_date_time,103),a.mg_exit_po,b.net_weight,a.puc,C.vendor_code

from main_gate_rm_entry_table a inner join weightment_entry_rm b OUTER JOIN pur_po_header C
on a.unloading_no = b.unloading_no
where a.company = @company_no
and a.entry_no = b.entry_no
and convert(datetime,(rtrim(substring(b.tare_time,1,11))),103) between @date_from AND @date_to
order by ul_po_no



declare @row_no int,
@tot_row int

select @tot_row = (select count(*) from #MAINGATE_RM)
select @row_no = 1
set rowcount 1

while (@row_no<= @tot_row)
begin
update #MAINGATE_RM
set sl_no = @row_no
where isnull(sl_no,0) = 0
select @row_no = @row_no + 1
end
set rowcount 0
select *,@date_from[FROM_DATE], @date_to[to_DATE],@HEADING[HEADING] from #MAINGATE_RM

END

THE C TABLE I NEED TO ATTACHED WITH a and b BUT HAVING MATCHING ONLY COMPANY_NO AND LOCATION_NO .......PLS HELP TO FIND THE SOLUTION......

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-06-22 : 10:10:58
Can't say much without seeing your data...but maybe this?

select a.company,a.location,a.unloading_no,a.entry_no,a.material,a.ul_po_no,CONVERT(DATETIME,a.ul_date_time,108),a.truck,
a.ven_name,a.mg_entry_check_by,CONVERT(DATETIME,a.mg_entry_date_time,103),a.mg_entry_po,
CONVERT(DATETIME,a.gross_date_time,103),a.gross_time_po,CONVERT(DATETIME,a.tare_date_time,103),
a.tare_time_po,CONVERT(DATETIME,a.mg_exit_date_time,103),a.mg_exit_po,b.net_weight,a.puc,C.vendor_code

from main_gate_rm_entry_table a inner join weightment_entry_rm b
on a.unloading_no = b.unloading_no and a.entry_no = b.entry_no
left join pur_po_header C on c.company_no = a.company_no
where a.company = @company_no
and convert(datetime,(rtrim(substring(b.tare_time,1,11))),103) between @date_from AND @date_to
order by ul_po_no
Go to Top of Page

avijit111@gmail.com
Yak Posting Veteran

55 Posts

Posted - 2009-06-23 : 01:39:59
quote:
Originally posted by avijit111@gmail.com

--MAINGATE_RM 'MEHTASCL','RNV',1,'2009/01/01','2009/01/24'
ALTER PROCEDURE MAINGATE_RM
(
@company_no glcompany,
@location_no gllocn,
@lang_id int,
@date_from datetime,
@date_to datetime
)
as

declare @today datetime, @HEADING varchar(60)

select @today = @date_to
begin

create table #MAINGATE_RM
(
sl_no int,
company GLCOMPANY,
location GLLOCN,
unloading_no varchar(18),
entry_no varchar(3),
material varchar(60),
ul_po_no varchar(18),
ul_date_time varchar(25),
truck varchar(15),
ven_name varchar(100),
mg_entry_check_by varchar(20),
mg_entry_date_time varchar(25),
mg_entry_po varchar(18),
gross_date_time varchar(25),
gross_time_po varchar(18),
tare_date_time varchar(25),
tare_time_po varchar(18),
mg_exit_date_time varchar(25),
mg_exit_po varchar(18),
net_weight numeric(9),
puc varchar(10),
vendor_code cmn_cust_ven_code
)

SELECT @heading = 'MAINGATE REPORT'

insert into #MAINGATE_RM(company,location ,unloading_no,entry_no,material,ul_po_no,ul_date_time,
truck,ven_name,mg_entry_check_by,mg_entry_date_time, mg_entry_po,gross_date_time,gross_time_po,tare_date_time,
tare_time_po,mg_exit_date_time,mg_exit_po,net_weight,puc,vendor_code )

select a.company,a.location,a.unloading_no,a.entry_no,a.material,a.ul_po_no,CONVERT(DATETIME,a.ul_date_time,108),a.truck,
a.ven_name,a.mg_entry_check_by,CONVERT(DATETIME,a.mg_entry_date_time,103),a.mg_entry_po,
CONVERT(DATETIME,a.gross_date_time,103),a.gross_time_po,CONVERT(DATETIME,a.tare_date_time,103),
a.tare_time_po,CONVERT(DATETIME,a.mg_exit_date_time,103),a.mg_exit_po,b.net_weight,a.puc,C.vendor_code

from main_gate_rm_entry_table a inner join weightment_entry_rm b OUTER JOIN pur_po_header C
on a.unloading_no = b.unloading_no
where a.company = @company_no
and a.entry_no = b.entry_no
and convert(datetime,(rtrim(substring(b.tare_time,1,11))),103) between @date_from AND @date_to
order by ul_po_no



declare @row_no int,
@tot_row int

select @tot_row = (select count(*) from #MAINGATE_RM)
select @row_no = 1
set rowcount 1

while (@row_no<= @tot_row)
begin
update #MAINGATE_RM
set sl_no = @row_no
where isnull(sl_no,0) = 0
select @row_no = @row_no + 1
end
set rowcount 0
select *,@date_from[FROM_DATE], @date_to[to_DATE],@HEADING[HEADING] from #MAINGATE_RM

END

THE C TABLE I NEED TO ATTACHED WITH a and b BUT HAVING MATCHING ONLY COMPANY_NO AND LOCATION_NO .......PLS HELP TO FIND THE SOLUTION......



ok i will send u the data.....
company
locno
key_value
unloading_no
entry_no
trans_code
challan_no
challan_qty
gross_weight
tare_weight
trans_name
gross_time
tare_time
weight_no
net_weight
chalan_date
chalan_time
SELECTION
these are the table from b and below from a.
company
location
key_value
unloading_no
entry_no
ul_po_no
ul_date_time
ven_code
ven_name
truck
material
mg_entry_check_by
mg_entry_date_time
mg_entry_po
gross_date_time
gross_time_po
tare_date_time
tare_time_po
mg_exit_check_by
mg_exit_date_time
mg_exit_po
puc


and below from c---
company_code
locn_no
po_no
amend_no
amend_date
amend_reference
amend_desc
ack_no
ack_date
ack_remarks
po_date
po_type
po_category
po_mode
buyer_code
module_id
po_status
onetime_vendor_flag
po_close_date
vendor_code
payto_vendor
pay_term_no
advance_payable
advance_paid
schedule_flag
delivery_date
shipment_flag
gi_flag
quality_indicator
base_curr_value
po_value
po_addnl_value
po_total_value
tr_currency_code
tr_exchange_rate
quot_no
reason
payment_mode
ins_liability
ins_term
ins_amount
valid_from
valid_to
allocated_amount
remaining_amount
lc_applicable_flag
last_nego_date
last_ship_date
trans_ship_flag
part_ship_flag
authorise_user_name
authorise_date
prev_po_status
ap_locn_no
fob_point
where_used
payment_flag
freeze_date
inco_terms
fs_fund_number
asset_locn
asset_id
cc_allocate_flag
remarks
create_locn_no
created_date
user_id
modified_date
modified_user_id
timestamp
vat_desirable
vat_inclusive
vat_category
vat_class

now i think u could do something for me......pls
Go to Top of Page

avijit111@gmail.com
Yak Posting Veteran

55 Posts

Posted - 2009-07-09 : 09:17:07
in the table
------------
trans_name varchar(60)
how convert it in numeric,then sum all transporter names

help me solve it out.........
Go to Top of Page

vijayisonly
Master Smack Fu Yak Hacker

1836 Posts

Posted - 2009-07-09 : 12:04:30
sum(cast(trans_name as decimal(38,2)))

you need to group by some field while using the SUM operator.
Go to Top of Page

bklr
Master Smack Fu Yak Hacker

1693 Posts

Posted - 2009-07-10 : 01:20:13
http://www.sqlteam.com/article/writing-outer-joins-in-t-sql
Go to Top of Page

avijit111@gmail.com
Yak Posting Veteran

55 Posts

Posted - 2009-07-10 : 01:50:54
alter proc pur_weighttransport_reportsclrnv_IN
@company_code varchar(10),
@locn_code varchar(4),
@lang_id int,
@from_dt datetime,
@to_date datetime,
@filter varchar(3)

as
begin
set nocount on

declare @todate datetime

select @todate = @to_date

create table #wbencloser
(
company GLCOMPANY,
locno GLLOCN,
challan_no varchar(25),
challan_qty cmn_Pqty,
weight_no cmn_tranno,
vehicle_no varchar(15),
gross_weight numeric(12,3),
TARE_weight numeric(12,3),
net_weight numeric(12,3),
remarks varchar(25),
unloading_no varchar(20),
entry_no cmn_slno,
unloading_date datetime,
vendor_code varchar(10),
vendor_name varchar(60),
item_code varchar(10),
variant_code varchar(4),
item_desc varchar(100),
po_no varchar(40),
GROSS_time datetime,
vendor_city varchar(25),
ship_fr CMN_DESCRIPTION,
trans_name varchar(60)
)

create table #wbencloser_mtd -- MONTH TO DATE DATA TABLE
(
nooftrip int,
vendor_code varchar(10),
challan_qty cmn_Pqty,
net_weight numeric(12,3),
vendor_name varchar(60),
item_code varchar(10),
variant_code varchar(4),
item_desc varchar(100),
vendor_city varchar(25),
ship_fr varchar(60),
trans_name varchar(60)

)

create table #wbencloser_today -- TODAY DATA TABLE
(
nooftrip int,
vendor_code varchar(10),
challan_qty cmn_Pqty,
net_weight numeric(12,3),
vendor_name varchar(60),
item_code varchar(10),
variant_code varchar(4),
item_desc varchar(120),
vendor_city varchar(25),
ship_fr varchar(60),
trans_name varchar(60)

)

create table #wbencloser_final -- FINAL DATA TABLE
(
vendor_name varchar(60),
item_desc varchar(120),
nooftrip_today int,
nooftrip_mdt int,
rec_qty_today numeric(12,3),
rec_qty_mtd numeric(12,3),
ch_qty_today numeric(12,3),
ch_qty_mtd numeric(12,3),
item_code varchar(10),
variant_code varchar(4),
vendor_city varchar(25),
vendor_code varchar(10),
ship_fr varchar(60) ,
new_vendor_city varchar(25),
trans_name varchar(60)

)

--pck brgin--
if (@filter ='OUT') --pck
begin
insert into #wbencloser (company,locno,challan_no, challan_qty, weight_no,
gross_weight, tare_weight, net_weight,unloading_no,
entry_no, GROSS_time,trans_name)
select company,locno,challan_no, challan_qty, weight_no, gross_weight,
tare_weight,net_weight, unloading_no,
entry_no, convert(char(11),tare_time,103),trans_name

from weightment_entry_rm (NOLOCK)
where company = @company_code
and locno = @locn_code
and gross_weight > 0.00
and tare_weight > 0.00
and convert(datetime,substring(tare_time,1,11),103) between @from_dt and @to_date
end
else
begin
insert into #wbencloser (company,locno,challan_no, challan_qty, weight_no,
gross_weight, tare_weight, net_weight,unloading_no,
entry_no, GROSS_time,trans_name)
select company,locno,challan_no, challan_qty, weight_no, gross_weight,
tare_weight,net_weight, unloading_no,
entry_no, convert(char(11),GROSS_time,103),trans_name
from weightment_entry_rm (NOLOCK)
where company = @company_code
and locno = @locn_code
and tare_weight = 0.00
and convert(datetime,substring(gross_time,1,11),103) between @from_dt and @to_date
end
--pck end--

--select * from #wbencloser
--return end


-- UPDATE FOR UNLAODING DATE
update #wbencloser
set unloading_date = a.unloading_date
from pur_unloading a, #wbencloser b
where a.company_code = @company_code
and a.locn_no = @locn_code
and a.unloading_no = b.unloading_no
and a.entry_no = b.entry_no




-- UPDATE FOR PO NO, VEHICLE NO AND VENDOR CODE
update #wbencloser
set po_no = a.po_no,
vehicle_no = a.vehicle_no,
vendor_code = a.vendor_code,
ship_fr = a.shipped_from
from pur_unloading a (nolock),#wbencloser b
where a.company_code = @company_code
and a.locn_no = @locn_code
and a.unloading_no = b.unloading_no
and a.entry_no = b.entry_no


-- UPDATE FOR VENDOR NAME AND CITY
update #wbencloser
set vendor_name = a.vendor_name,
vendor_city = a.city
from common..pur_company_vendor_master a (nolock),#wbencloser b
where a.company_code = @company_code
and a.vendor_code = b.vendor_code

-- UPDATE FOR ITEM CODE AND VARIANT CODE
update #wbencloser
set item_code = a.stock_no,
variant_code = a.stock_variant
from pur_po_detail a (nolock),#wbencloser b
where a.company_code = @company_code
and a.locn_no = @locn_code
and a.po_no = b.po_no

-- UPDATE FOR ITEM DESCRIPTION
update #wbencloser
set item_desc = a.description
from common..ims_variant_master a (nolock),#wbencloser b
where a.company_no = @company_code
and a.location_no = @locn_code
and a.stock_no = b.item_code
and a.variant_no = b.variant_code

-- INSERTION FOR MONTH TO DATE DATA TABLE
insert into #wbencloser_mtd( nooftrip, vendor_code,
challan_qty, net_weight, vendor_name,
item_code, variant_code,
item_desc, vendor_city, ship_fr,trans_name)
select count(*) nooftrip, min(vendor_code) vendor_code ,
sum(challan_qty) challan_qty, sum(net_weight) net_weight,
min(vendor_name) vendor_name, min(item_code) item_code,
min(variant_code) variant_code,
min(item_desc) item_desc, min(vendor_city) vendor_city, min(ship_fr) ship_fr,sum(cast(trans_name as decimal(38,2)))
from #wbencloser
where GROSS_time between @from_dt and @to_date
group by item_desc,vendor_code,ship_fr,trans_name





-- INSERTION FOR TODAY DATA TABLE
insert into #wbencloser_today(nooftrip, vendor_code,
challan_qty, net_weight, vendor_name,
item_code, variant_code ,
item_desc, vendor_city, ship_fr,trans_name )
select count(*) nooftrip, min(vendor_code) vendor_code ,
sum(challan_qty) challan_qty, sum(net_weight) net_weight,
min(vendor_name) vendor_name, min(item_code) item_code,
min(variant_code) variant_code,
min(item_desc) item_desc, min(vendor_city) vendor_city, min(ship_fr) ship_fr,sum(cast(trans_name as decimal(38,2)))
from #wbencloser
where GROSS_time = @todate
group by item_desc,vendor_code,ship_fr,trans_name





-- INSERTION FOR FINAL DATA TABLE
insert into #wbencloser_final(trans_name ,vendor_name, item_desc,item_code, variant_code, vendor_city, vendor_code, ship_fr)
select trans_name ,vendor_name, item_desc, item_code, variant_code, vendor_city, vendor_code, ship_fr
from #wbencloser_mtd


-- UPDATION FOR FINAL TABLE FROM MONTH TO DATE AND TODAY DATA TABLE
update #wbencloser_final
set nooftrip_mdt = a.nooftrip
from #wbencloser_mtd a, #wbencloser_final b
where a.vendor_code = b.vendor_code
and a.item_desc = b.item_desc
and a.ship_fr = b.ship_fr


update #wbencloser_final
set nooftrip_today = a.nooftrip
from #wbencloser_today a, #wbencloser_final b
where a.vendor_code = b.vendor_code
and a.item_desc = b.item_desc
and a.ship_fr = b.ship_fr


update #wbencloser_final
set rec_qty_mtd = a.net_weight
from #wbencloser_mtd a, #wbencloser_final b
where a.vendor_code = b.vendor_code
and a.item_desc = b.item_desc
and a.ship_fr = b.ship_fr

update #wbencloser_final
set rec_qty_today = a.net_weight
from #wbencloser_today a, #wbencloser_final b
where a.vendor_code = b.vendor_code
and a.item_desc = b.item_desc
and a.ship_fr = b.ship_fr

update #wbencloser_final
set ch_qty_mtd = a.challan_qty
from #wbencloser_mtd a, #wbencloser_final b
where a.vendor_code = b.vendor_code
and a.item_desc = b.item_desc
and a.ship_fr = b.ship_fr

update #wbencloser_final
set ch_qty_today = a.challan_qty
from #wbencloser_today a, #wbencloser_final b
where a.vendor_code = b.vendor_code
and a.item_desc = b.item_desc
and a.ship_fr = b.ship_fr

update #wbencloser_final
set new_vendor_city = ship_fr
where vendor_city != ship_fr

-- FINAL SELECT STATEMENT

select
trans_name,
vendor_name ,
item_desc ,
nooftrip_today ,
nooftrip_mdt ,
rec_qty_today ,
rec_qty_mtd , ch_qty_today ,
ch_qty_mtd ,
item_code ,
variant_code ,
vendor_city ,
new_vendor_city,
vendor_code ,
ship_fr,
@from_dt from_date, @to_date to_date
from #wbencloser_final
order by item_desc,vendor_code,ship_fr

end

error giving----
Error converting data type varchar to numeric.
i would like to sum same trans_name and their values.like nooftrip,today and monthly,and rec_qty_today and mtd,ch_qty_today and mtd,means one trans_name and all other trip value sum will come...



try to help me out pls..........





Go to Top of Page

avijit111@gmail.com
Yak Posting Veteran

55 Posts

Posted - 2009-07-16 : 10:17:54
hi to all...
i would like to know how to customize the registration_no within some numbers...
i m having one uds screen...

there are two coding part...
1st is........HEADER APPLY STORED PROCEDURE NAME
CREATE PROCEDURE em_vend_det_hdr_ins11
( @udsid char(10),
@screenid varchar(10),
@company_code glcompany,
@location_code gllocn,
@langid smallint,
@mode tinyint,
@key_value varchar(255),
@vendor_no char(22),
@register_no char(50)

)
AS
BEGIN


if ( LEN (@register_no) < 15)
begin
select '88888','error'
end
else
begin
select '99999','good'
end
END


and 2nd one from fetching the data is.....HEADER FETCH STORED PROCEDURE NAME...



CREATE PROCEDURE em_vend_det_hdr_sel
( @udsid char(10),
@screenid varchar(10),
@company_code glcompany,
@location_code gllocn,
@langid smallint,
@mode tinyint,
@key varchar(255),
@vendor_no char(16)

)
AS
BEGIN
DECLARE @excise_reg BIT,
@user_id cmn_userid

SELECT @user_id = user_id()

EXEC @excise_reg = common..em_interface_activation_check
@company_code ,
@location_code ,
@langid ,
@user_id ,
'POM' ,
'B'

IF (@excise_reg = 0) /* IF EM Nor Registered Do Not Launch The Screen */
BEGIN
SELECT '88888','EM Not Registered'
RETURN
END

DECLARE @pos int,
@len_temp int,
@count_temp int


SELECT @key = NULLIF(RTRIM(@key),'')
SELECT @vendor_no = NULLIF(RTRIM(@vendor_no),'')

SELECT @len_temp = DATALENGTH(@key)

IF (@len_temp = 0)
BEGIN
SELECT @len_temp = 1
END

SELECT @count_temp = 0
WHILE (@count_temp < 3)
BEGIN
SELECT @pos = CHARINDEX('~', ISNULL(@key,''))
SELECT @key = SUBSTRING(@key, (@pos + 1), (@len_temp - @pos))
SELECT @count_temp = @count_temp + 1
END


IF EXISTS (SELECT 'X'
FROM common..em_cust_ven_stax_detail
WHERE company_code = @company_code
AND locn_no = @location_code
AND cust_ven_flag = 'V'
AND cust_ven_no = @vendor_no)
BEGIN
SELECT '99999',1001,cust_ven_no,1002,register_no
FROM common..em_cust_ven_stax_detail
WHERE company_code = @company_code
AND locn_no = @location_code
AND cust_ven_flag = 'V'
AND cust_ven_no = @vendor_no
GROUP by cust_ven_no,register_no
END

END
how to customize the registration_no greater than 10 and less than 50
and if both the condition will broke give error.........
table value is ...
em_cust_ven_stax_detail
cust_ven_no SERVICE_HEAD REGISTER_NO
---------- ------------ ------------
V
V
V
THE 2ND TABLE IS
em_interface_activation_check---
PARAMETER_NAME
@company_code
@location_code
@lang_code
@user_id
@base_app_code
@be_fe_flag

PARAMETER_TYPE
--------------
GLCOMPANY
GLLOCN
cmn_langid
cmn_userid
cmn_app_code
cmn_flag



pls tell me how to solve me out...












Go to Top of Page
   

- Advertisement -