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 |
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-09-18 : 11:53:28
|
Hi AllI would like to execute a set of sql statements based a value that is returned from a select statement.I am not sure whether i can use a case statement in this scenario.based on the value of frequency returned in the below select i would like to execute differant logics.How do i accomplish itSELECT Reqno,frequency from customerinfo where reqno in = 148694CASE frequencyWhen 'Monthly' ThenWHILE @@FETCH_STATUS = 0 BEGIN --do work here set @count=0WHILE @count < @num_of_times BEGIN update table_keysset key_id = key_id + 1 where table_name = 'adhoc'ELSEWHILE @@FETCH_STATUS = 0 BEGIN --do work here set @count=0WHILE @count < @num_of_times BEGIN update table_keysset key_id = key_id + 2 where table_name = 'adhoc'END |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-18 : 12:54:57
|
| sorry posted code doesnt make any sense to mecan you explain what exactly you're trying to do here?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
jim_jim
Constraint Violating Yak Guru
306 Posts |
Posted - 2012-09-18 : 13:43:31
|
| Iam trying to perform insertions to differant tables in our database based on the value of the frequency returned from a select statement.ignore the code that i have after the select stamtementjust want to know how to write a case statement based on the frequency value i get from SELECT Reqno,frequency from customerinfo where reqno in = 148694 |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2012-09-18 : 14:16:30
|
| case statement for what? getting variable value for iteration? how will case returned value be used?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|