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
 Simpler way to write store procedure

Author  Topic 

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-01-25 : 10:11:54
What's a simpler way to write this?



select mnth_endt, sum(zip_count) as iCnt
from [dbo].[iClaimsTemp]
where typ_of_actn='a' and abap_prc_cd <> 'y' and abap_prc_cd <> 's' and (Bicnum='002' or Bicnum='010') and inet_ind = '1'
Group by mnth_endt


Thanks!

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-01-25 : 10:23:25
select mnth_endt, sum(zip_count) as iCnt
from [dbo].[iClaimsTemp]
where typ_of_actn='a' and abap_prc_cd NOT IN('y','s') and Bicnum IN('002','010') and inet_ind = '1'
Group by mnth_endt
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-01-25 : 10:49:47
Thanks!
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-01-25 : 11:02:25
I have another one please...



select mnth_endt, sum(zip_count) as iCnt
from [dbo].[iClaimsTemp]
where ((Typ_Of_Actn = 'A' and Inet_Ind = 'M') ||
(Inet_Ind == '1' && Bicnum == '202')
|| (Inet_Ind == '4' && (Bicnum == '203' || Bicnum == '204')) &&(Abap_Prc_Cd == 'S' || Abap_Prc_Cd == 'Y')


Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-01-25 : 11:17:26
What's with the || and &&? Is this something other than SQL Server?
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-01-25 : 11:38:46
No it's SQL but the person who wrote this is use to using Access so he wrote the procedure as such. I want to use this in SQL 2005.
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-01-25 : 11:49:58
Is this okay?


Type of actn='a' and inet-ind = 'n' and bicnum in ('010', '202', '203', '204') or bicnum = '002' and inet_ind = 'n' and abap_prc_cd in ('s', 'y)
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-01-25 : 12:07:27
Probably, although mixing the AND and OR operations like that may not return the correct results.
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-01-25 : 13:52:28
How could I combine them together?
Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-01-25 : 14:00:09
Basically just be aware of the parentheses surrounding/nesting them in the original, make sure they are maintained.
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-01-25 : 14:18:53
How's this?



((Type of actn='a' and inet-ind = 'n' and bicnum in ('010', '202', '203', '204')) or (bicnum = '002' and inet_ind = 'n' and abap_prc_cd in ('s', 'y')))

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2011-01-25 : 14:38:13
It looks correct but you really need to compare the results to the original to be sure.
Go to Top of Page

JJ297
Aged Yak Warrior

940 Posts

Posted - 2011-01-25 : 14:48:05
Okay I have to do so in the morning when I run my file to add in a column that was just added. Thanks.
Go to Top of Page
   

- Advertisement -