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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 select query to multiple condition

Author  Topic 

amirs
Constraint Violating Yak Guru

260 Posts

Posted - 2011-10-11 : 03:13:05
Dear member
i have read a following table
cust orno ordqty delqty balqty pos
A 50 7 7 0 1
A 50 7 7 0 2
A 50 2 2 0 3
A 50 2 2 0 4
A 50 2 2 0 5
A 50 1 1 0 6
B 51 8 0 0 1
B 51 8 0 0 2
B 51 1 0 0 3
B 51 2 0 0 4
B 51 1 0 0 5
B 51 1 0 0 6
B 51 1 0 0 7
C 53 10 10 0 1
C 53 10 10 0 2
C 53 3 3 0 3
C 53 3 3 0 4
C 53 2 2 0 5
C 53 2 2 0 6
C 53 10 10 0 7
D 54 10 10 0 1
D 54 10 10 0 2
D 54 2 2 0 3
D 54 2 2 0 4
D 54 3 3 0 5
D 54 3 3 0 6

i have find the newqty record of one table to following condition
If orno <> prevord Or pos <> prvpos Then
If ordqty - delqty > 0 Then
If delqty = 0 Then
If balqty <> 0 Then
newqty = balqty
Else
newqty = ordqty
End If
Else
If balqty <> 0 Then
newqty = balqty
Else
If invn = 0 Then
newqty = delqty
Else
newqty = 0
End If
End If
End If
End If

End If
prevord = orno
prvpos = pos

i have write this condition within application to find records.
but this is very slow working because i have read near about 100000 record at a time and this condition is work is very slow.
so it is possible to write this condition to creating a views in sql.
i am using sql2005

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2011-10-11 : 03:45:59
try

select newqty = case when delqty = 0
then
case when balqty <> 0
then balqty
else ordqty
end
else
case when balqty <> 0
then
case when invn = 0
then delqty
else 0
end
end
end
from yourtable
where ( orno <> prevord Or pos <> prvpos )
and ( ordqty - delqty > 0 )



KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -