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 2005 Forums
 Transact-SQL (2005)
 Creating Stored Procedure

Author  Topic 

CoachBarker
Posting Yak Master

170 Posts

Posted - 2009-01-06 : 08:44:30
Again this is the procedure I am using in my report, and through trial and error I am slowly putting it together.

SELECT detail_record.division, detail_record.pickup_weight, detail_record.pickup_dt,detail_record.customer_delv_to,
detail_record.customer_bill_to, customer_master.customer_number, customer_master.customer_name,
customer_master.city, detail_record.pickup_date, detail_record.ticket_number

FROM detail_record INNER JOIN
customer_master ON detail_record.customer_bill_to = customer_master.customer_number AND
detail_record.customer_delv_to = customer_master.customer_number

WHERE (detail_record.customer_bill_to = @customer_number) AND (detail_record.customer_delv_to = @customer_number) AND
(detail_record.pickup_date BETWEEN @StartDate AND @EndDate)

ORDER BY detail_record.division, detail_record.pickup_weight

What I need the SPROC to do is get the customer_name based on the customer_number from the customer_master table being equal to detail_record.customer_bill_to and
detail_record.customer_delv_to (they are both cutomer_numbers)

Thanks for the help
CoachBarker

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 08:54:43
According to your explanation, your code looks fine. so will detail_record.customer_bill_to & detail_record.customer_delv_to always have same value? also whats the problem you're facing?
Go to Top of Page

CoachBarker
Posting Yak Master

170 Posts

Posted - 2009-01-06 : 09:08:24
No BillTo and DelvTo can be different .I want to return the CustomerName based on the Number so I can set the value of the textboxes to CustomerName

Thanks for the help
CoachBarker
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 09:39:08
quote:
Originally posted by CoachBarker

No BillTo and DelvTo can be different .I want to return the CustomerName based on the Number so I can set the value of the textboxes to CustomerName

Thanks for the help
CoachBarker


then shouldnt you be returning two customer names one corresponding to each id. Also, whats the purpose of below where condition in which you're looking for only records with both values same as passed parameter value?

WHERE (detail_record.customer_bill_to = @customer_number) AND (detail_record.customer_delv_to = @customer_number)


Go to Top of Page

CoachBarker
Posting Yak Master

170 Posts

Posted - 2009-01-06 : 10:11:50
quote:
then shouldnt you be returning two customer names one corresponding to each id. Also, whats the purpose of below where condition in which you're looking for only records with both values same as passed parameter value?

WHERE (detail_record.customer_bill_to = @customer_number) AND (detail_record.customer_delv_to = @customer_number)



I changed the WHERE clause back to the original right after I posted. That is what I am trying to figure, return 2 customer names from the existing query.

Thanks for the help
CoachBarker
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-01-06 : 10:42:20
[code]
SELECT detail_record.division, detail_record.pickup_weight, detail_record.pickup_dt,detail_record.customer_delv_to,
detail_record.customer_bill_to, cm1.customer_number, cm1.customer_name,cm1.city,cm2.customer_number, cm2.customer_name,
cm2.city, detail_record.pickup_date, detail_record.ticket_number

FROM detail_record INNER JOIN
customer_master cm1 ON detail_record.customer_bill_to = cm1.customer_number
INNER JOIN
customer_master cm2 ON detail_record.customer_delv_to = cm2.customer_number
.....
......
[/code]
Go to Top of Page

CoachBarker
Posting Yak Master

170 Posts

Posted - 2009-01-06 : 14:50:26
That works much better thanks, I forgot all about creating pseudo tables, I had only done it a few times in school.

Thanks for the help
CoachBarker
Go to Top of Page
   

- Advertisement -