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.
| Author |
Topic |
|
ashley.s
Starting Member
9 Posts |
Posted - 2012-06-19 : 06:32:45
|
| Hi everyone, I have 3 tables as followsTable 1ClientID ClientName1 ABC2 XYZTable 2InvoiceNum DateV001 20/05/12V002 21/05/12Table 3ClientID InvoiceNum1 V0012 V002I need to find the invoicenum and date for a specific clientname. I am stuck on this.If i do,Select clientid from table1 where clientname=ABCthenI have to use that result to look for the invoicenum and date. Is it possible to do all that in a query?Regards,Ashley |
|
|
nigelrivett
Master Smack Fu Yak Hacker
3385 Posts |
Posted - 2012-06-19 : 06:38:18
|
| select t2.*from Table1 t1join Table3 t3on t1.ClientID = t3.ClientID join Table2 t2on t3.InvoiceNum = t2.InvoiceNumwhere t1.ClientName = 'ABC'==========================================Cursors are useful if you don't know sql.SSIS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
ashley.s
Starting Member
9 Posts |
Posted - 2012-06-19 : 07:24:09
|
| Hi nigel,thank you so much.I tried out something similar. Thank you so much. Can you look into my query below? i am doing the sum of a column.select InvDetails.InvoiceNo,InvDetails.FileRef, InvDetails.Remarks, Inv.Name, Inv.Date, sum(InvAmt.Amount) from InvDetails inner join Client on InvDetails.ClientID = Client.ClientID inner join Inv on Inv.InvoiceNo = InvDetails.InvoiceNo inner join InvAmt on InvAmt.InvoiceNo = InvDetails.InvoiceNo where Client.[Client's Name]='SLX nTech-Vision Ltd' group by InvDetails.InvoiceNo I am getting this errorColumn 'InvDetails.FileRef' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.Can you please advise?Sorry if i am posting on the same thread. |
 |
|
|
DonAtWork
Master Smack Fu Yak Hacker
2167 Posts |
Posted - 2012-06-19 : 09:48:51
|
| A SUM is an aggregate function. All of the other columns in your select either have to also be aggregated, or be put into a GROUP BY.You may wish to try this link. It could help a great deal. http://www.w3schools.com/sql/default.aspHow to ask: http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxFor ultra basic questions, follow these links.http://www.sql-tutorial.net/ http://www.firstsql.com/tutor.htm http://www.w3schools.com/sql/default.asp |
 |
|
|
|
|
|