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 |
|
dundealing
Starting Member
12 Posts |
Posted - 2007-10-25 : 12:03:18
|
| Hi,I am trying to iterate through the rows in a temporary table and get the rowcount from a different table based on a certain value?For example, I have a temp table with 5 columns. I have populated 4 columns with the values from table A. I now need to fill the final column with the count(*) from table B where an ID is the same as that in the temp table's first column.It goes something like this:Create table #temp(A char,B char,C char,D char)insert #temp (A,B,C,D)select A, B, C, D from dbo.AlphabetI now need to insert into #temp the count of all rows in table dbo.Words where WordsID = whatever is in the A column, and I need to do this for every row in #temp.I tried a while loop but it threw up some syntax errors.Any help would be much appreciated. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2007-10-25 : 12:11:37
|
| update #tempset cnt = (select count(*) from Words where #temp.A = Words.WordsID)==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
dundealing
Starting Member
12 Posts |
Posted - 2007-10-28 : 09:06:35
|
| Many thanks,nr, that looks good to me.X002548, it isn't an assignment, I am just new to SQL. |
 |
|
|
|
|
|
|
|