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 2000 Forums
 Transact-SQL (2000)
 Output from an SQL string with a JOIN and a GROUP BY

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2001-09-14 : 15:31:57
Chad writes "My scenario is as follows: One(1)member with a unique account number visits several restaurants. Each restaurant has a unique code. In my database, one table has the member id and the unique code number of the restaurant visited. Another table has the code number of the restaurant AND the description of the restaurant. In my SQL string I have the tables joined at the code. Since I only want to see the occurrence of each member and each restaurant only once, I used the Group By feature. In a simple SELECT query it is easily understood how you walk through each record and either Response.Write it or not, but in this case, how do I output the results when there is some aggregation going on?

The code looks like this: (by the way membernumber is retrieved from a previous form element)

strSQL = "SELECT AG_TWEN_TEMP1.ACCT_NR, AG_TWE_PROM.BRND_DESC"
strSQL = strSQL & " FROM AG_TWEN_TEMP1 INNER JOIN AG_TWE_PROM ON AG_TWEN_TEMP1.BRAND = AG_TWE_PROM.BRAND"
strSQL = strSQL & " GROUP BY AG_TWEN_TEMP1.ACCT_NR, AG_TWE_PROM.BRND_DESC"
strSQL = strSQL & " HAVING AG_TWEN_TEMP1.ACCT_NR = '"& membernumber &"'"

SQL version 7 (I think)

Thank you!

Chad"
   

- Advertisement -