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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 updating based on case statement

Author  Topic 

jim_jim
Constraint Violating Yak Guru

306 Posts

Posted - 2012-09-18 : 11:53:28
Hi All
I 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 it

SELECT Reqno,frequency from customerinfo where reqno in = 148694

CASE frequency
When 'Monthly' Then

WHILE @@FETCH_STATUS = 0
BEGIN

--do work here




set @count=0
WHILE @count < @num_of_times
BEGIN

update table_keys
set key_id = key_id + 1
where table_name = 'adhoc'

ELSE

WHILE @@FETCH_STATUS = 0
BEGIN

--do work here




set @count=0
WHILE @count < @num_of_times
BEGIN

update table_keys
set 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 me

can you explain what exactly you're trying to do here?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

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 stamtement

just 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

Go to Top of Page

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 MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -