| Author |
Topic |
|
karuna
Aged Yak Warrior
582 Posts |
Posted - 2005-05-11 : 12:41:09
|
This is my query:Select col1,col2,col3 from TblA where condition1union allSelect col4,col5,col6 from TblA where condition2union allselect col7,col8,col9 from TblA where condition3Update TblA set col10 = somevalue where Condition1Update TblA set col10 = someothervalue where Condition2Update TblA set col10 = anothervalue where Condition3 I need to run my first update query when my first select statement returns some value, the same with the other 2 select and updatesI tried this:Declare @rc intSelect col1,col2,col3 from TblA where condition1set @rc = @@rowcountIf(@rc >0 )BeginUpdate TblA set col10 = somevalue where Condition1End Union allDeclare @rc intSelect col4,col5,col6 from TblA where condition2set @rc = @@rowcountIf(@rc >0 )BeginUpdate TblB set col10 = somevalue where Condition2End Union allDeclare @rc intSelect col7,col8,col9 from TblA where condition3set @rc = @@rowcountIf(@rc >0 )BeginUpdate TblB set col10 = somevalue where Condition3End This gives me error. Any other way to do this?Karunakaran___________It's better to be loved and lost, than ever to be loved... |
|
|
vijayakumar_svk
Yak Posting Veteran
50 Posts |
Posted - 2005-05-12 : 05:56:18
|
| I dont know this will help you.. Please have a trycreate table TblA(Col1 int,Col2 int,Col3 int,Col4 int,Col5 int,Col6 int,Col7 int,Col8 int,Col9 int,Col10 int)insert into TblA values(1,2,3,4,5,6,7,8,9,10)insert into TblA values(11,12,13,14,15,16,17,18,19,20)insert into TblA values(21,22,23,24,25,26,27,28,29,30)Select col1,col2,col3 from TblA where col1=4union allSelect col4,col5,col6 from TblA where col2=2union allselect col7,col8,col9 from TblA where col3=3Update TblA set col10 = 40 where col1=1and 1=(Select count(*)/case count(*) when 0 then 1 else count(*) end from TblA where col1=4)Update TblA set col10 = 50 where Condition2Update TblA set col10 = 60 where Condition3------------------Work smarter not harder take control of your life be a super achiever |
 |
|
|
|
|
|