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 |
|
psystems
Starting Member
8 Posts |
Posted - 2005-08-08 : 13:08:16
|
| I need to get a record count from 2 different tables and update a temp table. I get an "incorrect syntax near '*' error on the below. Is it not possible to use an alias with the count function?Any suggestions?Thank you.CREATE TABLE #tmpTableCount (TableName varchar(50) not null, CCount int not null, ImportCount int not null)Select 'TestTable', count(ot.*), count(tt.*) INTO #tmpTableCount FROM TestTable AS tt INNER JOIN OldTable as ot ON tt.SKey = ot.SKey |
|
|
nathans
Aged Yak Warrior
938 Posts |
Posted - 2005-08-08 : 13:14:54
|
Which count do you want? The rowcount of the two independent tables or the row count of the rows that met the join criteria?You are using an inner join, so a count on either table in that query would be equal, so just use count(*).If you want discrete counts try:Select 'TestTable', ot_count = (select count(*) from oldTable), tt_count = (select count(*) from testTable) INTO #tmpTableCount Nathan Skerl |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2005-08-08 : 13:22:06
|
| [code]SELECT* * INTO #mytemp99 FROM ( Select 'TestTable' AS TableSource, count(*)AS RowCount FROM TestTable AS ttUNION ALL Select 'OldTable' AS TableSource, count(*)AS RowCount) AS XXX[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
 |
|
|
|
|
|