x

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 '12 at 01:09 AM in Default

jaa gravatar image

jaa
0 1 1 1

is this a homework question?
Feb 15 '12 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 '12 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][1] to get more insight.

[1]: http://msdn.microsoft.com/en-us/library/ms191517.aspx
more ▼

answered Feb 15 '12 at 05:16 AM

Usman Butt gravatar image

Usman Butt
13.9k 6 8 14

(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.

New code box

There's a new way to format code on the site - the red speech bubble logo will automatically format T-SQL for you. The original code box is still there for XML, etc. More details here.

Follow this question

By Email:

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

By RSS:

Answers

Answers and Comments

SQL Server Central

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

Topics:

x6

asked: Feb 15 '12 at 01:09 AM

Seen: 586 times

Last Updated: Feb 15 '12 at 05:16 AM