question

jaa avatar image
jaa asked

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.
query-analyzer
2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

is this a homework question?
0 Likes 0 ·
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.
0 Likes 0 ·

1 Answer

·
Usman Butt avatar image
Usman Butt answered
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][1] to get more insight. [1]: http://msdn.microsoft.com/en-us/library/ms191517.aspx
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.