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
 How does one column condition fire other column

Author  Topic 

chandusama
Starting Member

13 Posts

Posted - 2008-04-06 : 17:33:11
hi guyz,

i am having a doubt.
The problem i am facing is tht i have a table in which one column is a condition column and other column is action column. Now how can i give a condition such that if the condition is true the action must be fired.
This is like a if statement ...where if the condition is true the corresponding action in the table has to be fired

Can someone help me with this



Sama

rmiao
Master Smack Fu Yak Hacker

7266 Posts

Posted - 2008-04-06 : 17:57:44
Do you have sample data and the result like to get?
Go to Top of Page

chandusama
Starting Member

13 Posts

Posted - 2008-04-06 : 18:05:26
this is the table..

condition------------------------------------------Action
[A]>3 OR ([B]<15 AND [D] > 2)----------------------[E]=3
[B] > 3 AND [E] > 16.3 OR [F] < 12-----------------[G]=[B]*[C]
([A]+[D])>30 OR [F] > 12---------------------------[H]=14
[A] < 10-------------------------------------------[F]=[A]*[D]
[B] >= 6 ------------------------------------------[D]=B – 3

This is the table...now here i have to check each column....lik if i am checking 1st row and there are values assigned to all the variables....so if i am chkin 1st row n its true the action value must be fired....n if it is false it shld check the second row...n so on

Sama
Go to Top of Page

chandusama
Starting Member

13 Posts

Posted - 2008-04-07 : 00:34:15
can some one help me quickely

Sama
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-07 : 00:44:19
Use CASE WHEN.. for assigining value to each column
like
[E]=CASE WHEN [A]>3 OR ([B]<15 AND [D] > 2) THEN 3 END,
[G]= CASE WHEN [B] > 3 AND [E] > 16.3 OR [F] < 12 THEN [B] * [C] END,...
Go to Top of Page

chandusama
Starting Member

13 Posts

Posted - 2008-04-07 : 01:31:13
i should not use the condition and action lik that....
i am actually writing a stored procedure here where the 1st row in table is taken and the condition is checked ..if its true then the action must be fired

Sama
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-07 : 01:44:26
quote:
Originally posted by chandusama

i should not use the condition and action lik that....
i am actually writing a stored procedure here where the 1st row in table is taken and the condition is checked ..if its true then the action must be fired

Sama


you can use case constructs within select/update statements. If you need more help, can you post what exactly you're trying to do?

Go to Top of Page

chandusama
Starting Member

13 Posts

Posted - 2008-04-07 : 02:16:14
ok here is wat i exactly need

here is 1st table Attributes

A 1
B 6
C 3.5


and my second table rules

1 [A]>3 OR ([B]<15 AND [D] > 2)-------------[E]=3
2 [B] > 3 AND [E] > 16.3 OR [F] < 12--------[G]=[B]*[C]
3 ([A]+[D])>30 OR [F] > 12------------------[H]=14
4 [A] < 10----------------------------------[F]=[A]*[D]
5 [B] >= 6----------------------------------[D]=B – 3

i hav to write a stored procedure where in the rules table the 1st condition shld be checked ..corresponding to their values in the attributes table. for ex...in the ist condition since D is not yet known it skips the first row n goes to next row
in the 2nd row snice E and F are not known it skips this condition and so on lik tht it comes to last condition where condition will be true and by that the action can be enabled where D value can be known. After this it goes to first row condition and calculates all the values like that..On the way while v know all the attributes v must replace the attributes in table with their values.....like the first row shld be 1<3 or (3.5 < 15 and Dvalue >2)...and so onn





Sama
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-07 : 02:32:52
So what will be your table structures? Two tables with two columns?
Go to Top of Page

chandusama
Starting Member

13 Posts

Posted - 2008-04-07 : 02:40:08
yes two tables with two structures

1st table structure is
Attribute---varchar(40)
value ----real


and the second table is

condition----varchar
action ----varchar


Sama
Go to Top of Page

chandusama
Starting Member

13 Posts

Posted - 2008-04-07 : 21:41:18
ANYONE WHO CAN HELP

Sama
Go to Top of Page
   

- Advertisement -