Question

Good day.. Im having a hard time in converting from ms access sql to sql server 2005 sql query.. and here's my code :

UPDATE Data SET 
  Data.Mean =([std1]+[std2]+[std3]/
IIf((3+(([std1]=0)+([std2]=0)+([std3]=0)))>0,
  (3+(([std1]=0)+([std2]=0)+([std3]=0))),1) 
WHERE Data.ID=125

I think the best way to convert this is by using CASE WHEN STATEMENT or any suggestions/alternatives you already know?

Thank you in advance!

Was it helpful?

Solution

Try this

    UPDATE Data SET 
     Mean =([std1]+[std2]+[std3])/
    case when abs([std1])+abs([std2])+abs([std3])=0 then 1 else 
      3 + case [std1] when 0 then -1 else 0 end 
        + case [std2] when 0 then -1 else 0 end 
        + case [std3] when 0 then -1 else 0 end
    end
    WHERE ID=125

OTHER TIPS

UPDATE Data SET
Data.Mean =([std1]+[std2]+[std3]/
(CASE WHEN (3+(([std1]=0)+([std2]=0)+([std3]=0)))>0 
THEN (3+(([std1]=0)+([std2]=0)+([std3]=0)))
ELSE 1
END))
WHERE Data.ID=125
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top