-1

I had a validation script that used Loops and Arrays to validate the below question but we are not using the temp table anymore so I will not be able to do this validation that way anymore. And the loop used was based on the array so I can not re-work it to make it fit the new standard.

So I have been trying to figure out a different way to do this but I can not seem to wrap my head around it.

I have a form that has a variable named Type and it can have the values of (1, 2, -1). I need to write a validation script in sql that makes sure that every time a form is submitted it will have a 1 AND -1 in the form. If it does not have a 1 or -1 or neither then an error message occurs. I have an valid and non valid example of the type field.

Could some one suggest away to do this, I have tried IF statements, Loops and Joins but I can not seem to get it to work. The form process all the information at once and not line by line.

This may be a simple question but I have been thinking to long on it and I just wanted some outside opinions.

Example: Valid (because has 1 and -1)

  TYPE   
  1    
  2
  2
  -1
  2
  -1

Example: Not Valid (because does not have -1)

  Type
  1
  2
  2

So, I was thinking something like this could possible work but I can't figure it out all the way.

     SELECT 
       p.f_field, 
       CASE WHEN f_field = '1' THEN 
      (SELECT p.f_field
                  FROM table mytable p 
                      WHERE f_field = '1') > 1)
                      AND
                      ((SELECT n.f_field
                      FROM table mytable n
                      WHERE f_field ='-1') >1)))</UL>
       END AS NewFiled  
     FROM table mytable p
4

1 回答 1

0

我只用了一个简单的验证脚本就知道了

SELECT COUNT (type)
INTO xxx_counter
FROM my_table
WHERE type = '1'

SELECT COUNT (type)
INTO yyy_counter
FROM my_table
WHERE type ='-1'

IF xxx_counter = 0 或 yyy_counter = 0 THEN
Error = 'True'
END IF

于 2013-07-31T19:49:24.337 回答