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.
Author |
Topic |
amirs
Constraint Violating Yak Guru
260 Posts |
Posted - 2011-10-11 : 03:13:05
|
Dear memberi have read a following tablecust orno ordqty delqty balqty posA 50 7 7 0 1A 50 7 7 0 2A 50 2 2 0 3A 50 2 2 0 4A 50 2 2 0 5A 50 1 1 0 6B 51 8 0 0 1B 51 8 0 0 2B 51 1 0 0 3B 51 2 0 0 4B 51 1 0 0 5B 51 1 0 0 6B 51 1 0 0 7C 53 10 10 0 1C 53 10 10 0 2C 53 3 3 0 3C 53 3 3 0 4C 53 2 2 0 5C 53 2 2 0 6C 53 10 10 0 7D 54 10 10 0 1D 54 10 10 0 2D 54 2 2 0 3D 54 2 2 0 4D 54 3 3 0 5D 54 3 3 0 6i 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 = posi 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
|
tryselect 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 endfrom yourtablewhere ( orno <> prevord Or pos <> prvpos )and ( ordqty - delqty > 0 ) KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
|
|