Please help me with my query . . .

I am stuck on this problem and instead of wasting more hours trying different ways I thought I would ask for help.

"Write a SELECT statement that returns three columns: VendorName From the Vendors table DefaultAccountNo From the Vendors table Account Description From the GLAccounts table The result set should have one row for each vendor, with the account number and account description for that vendor's defaultaccount number. Sort the result set by AccountDescription, then by VendorName.

Below is my latest attempt at this but still has errors:

SELECT AccountDescription, VendorName, DefaultAccountNo FROM Vendors JOIN GLAccounts ON DefaultAccountNo = AccountNo WHERE GLAccounts.AccountDescription = Vendors.DefaultAccountNo ORDER BY AccountDescription, VendorName

Any help is appreciated.

more ▼

asked Feb 15, 2012 at 01:09 AM in Default

avatar image

0 1 1 1

is this a homework question?

Feb 15, 2012 at 01:12 AM Daniel Ross

Since you have put an effort to solve this, you deserve some help. But please let us know if it is the homework, so we can tag it correctly.

Feb 15, 2012 at 05:14 AM Usman Butt
(comments are locked)
10|1200 characters needed characters left

1 answer: sort voted first

You have already made the JOIN on both tables with seemingly correct fields i.e.

 ON DefaultAccountNo = AccountNo

So there is no need to have this statement in the WHERE clause

 WHERE GLAccounts.AccountDescription = Vendors.DefaultAccountNo 

Practically the above statement does not make sense as AccountDescription (e.g. "Expense Account") cannot be equal to DefaultAccountNo (e.g. 01000101). This is why an error would have been generated because of the non-compatible fields (Assuming DefaultAccountNo is numeric field and AccountDescription is a character field). I beleive you should visit BOL to get more insight.

more ▼

answered Feb 15, 2012 at 05:16 AM

avatar image

Usman Butt
14.9k 6 13 21

(comments are locked)
10|1200 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

SQL Server Central

Need long-form SQL discussion? SQLserverCentral.com is the place.



asked: Feb 15, 2012 at 01:09 AM

Seen: 983 times

Last Updated: Feb 15, 2012 at 05:16 AM

Copyright 2018 Redgate Software. Privacy Policy