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 |
|
vision99
Starting Member
14 Posts |
Posted - 2009-06-26 : 12:12:05
|
| Hi, I have one temp table, am inserting values from another tablecreate table #temp1( rowtitle varchar(50), [status] varchar(50), [countvalue] int)insert into #temp1( rowtitle, [status])select rowtitle, [status]from ctladastatusesI want to update [countvalue] field likeupdate #temp1set [countvalue] = (select distinct rowtitle from ctladastatuses) showing error msg.. while trying to update, plzz give some idea...-Vision |
|
|
jimf
Master Smack Fu Yak Hacker
2875 Posts |
Posted - 2009-06-26 : 12:18:13
|
| What are you trying to accomplish with this query? What error are you getting. One reason your update is failing is that (select distinct rowtitle from ctladastatuses) will return more than one value.Jim |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-26 : 12:19:25
|
update t1set [countvalue]=dt.cntfrom #temp1 t1join (select rowtitle,count(*) as cnt from ctladastatuses group by rowtitle)dton dt.rowtitle = t1.rowtitle No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
vision99
Starting Member
14 Posts |
Posted - 2009-06-26 : 12:46:40
|
quote: Originally posted by webfred update t1set [countvalue]=dt.cntfrom #temp1 t1join (select rowtitle,count(*) as cnt from ctladastatuses group by rowtitle)dton dt.rowtitle = t1.rowtitle No, you're never too old to Yak'n'Roll if you're too young to die.
Thanks for reply, but its not giving me the expected results i.e.,select count(distinct rowtitle) will retrive the value '7', so '7' should be updated for all records for [countvalue] field..-Vision |
 |
|
|
webfred
Master Smack Fu Yak Hacker
8781 Posts |
Posted - 2009-06-26 : 12:52:15
|
Then use your "count(distinct rowtitle)" in your formerly posted statement. No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-26 : 13:58:54
|
| [code]update tset [countvalue] = (select count(distinct rowtitle) from ctladastatuses where rowtitle = t.rowtitle) from #temp1 t[/code] |
 |
|
|
|
|
|
|
|