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 |
cojimarmiami
Starting Member
6 Posts |
Posted - 2014-05-22 : 12:30:38
|
I have a table with the following dataSHCOMP CBLNAM SHDESC SHAMT SHTYPE 123 cust1 desc1 45 A123 cust1 desc1 -45 D121 cust2 desc2 10 T121 cust2 desc3 -10 F121 cust2 desc3 10 A234 cust3 desc4 60 T234 cust3 desc4 -60 F234 cust3 desc5 30 A235 cust3 desc5 30 A235 cust4 desc6 -50 FI have a report on Crystal where I added NOTES and GROUP columnsI created those columns using this formula in Crystal.if {CUST.CSTRDT} >= tonumber(totext(({@firstday}-14),'yyyyMMdd')) and{CUST.CSTRDT} <= tonumber(totext(({@lastday}-7),'yyyyMMdd')) and {SHST.SHTYPE} = "A" then "New Customer" else if ({CUST.CSTRDT} <= tonumber(totext(({@firstday}-14),'yyyyMMdd')) or{CUST.CSTRDT} >= tonumber(totext(({@lastday}-7),'yyyyMMdd'))) and {SHST.SHTYPE} = "A" then "Services Added" else if {SHST.SHTYPE} = "D" then "Services Removed" elseif {@CUST#} = Previous({@CUST#}) and {SHST.SHDESC} = Previous({SHST.SHDESC}) and {SHST.SHAMT} > Previous({SHST.SHAMT}) then "Price Increase" elseif {@CUST#} = Previous ({@CUST#}) and {SHST.SHDESC} = Previous ({SHST.SHDESC}) and {SHST.SHAMT} < Previous ({SHST.SHAMT}) then "Price Decrease"Here is how my report looksSHCOMP CBLNAM SHDESC SHAMT SHTYPE NOTES GROUP123 cust1 desc1 45 A services added SA123 cust1 desc12 -45 D services removed SR121 cust2 desc2 10 T 121 cust2 desc2 -10 F price decrease PD121 cust2 desc2 10 A new customer NC234 cust3 desc4 -60 F 234 cust3 desc4 60 T price increase PI235 cust3 desc5 30 A 235 cust4 desc6 -50 F 235 cust4 desc6 70 T price increase PIwhat I need to create is an stored procedure that save in a temp table GROUP column and also another column that save the changed amount. For exampleGROUP AMOUNTNC 10PI 20PD 0 (if previous customer, service and amount are the same does not count because will be 0 balance)SR -45SA 45 |
|
Lamprey
Master Smack Fu Yak Hacker
4614 Posts |
Posted - 2014-05-22 : 12:38:56
|
I'm not sure I follow. Given this set of data:SHCOMP CBLNAM SHDESC SHAMT SHTYPE NOTES GROUP123 cust1 desc1 45 A services added SA123 cust1 desc12 -45 D services removed SR121 cust2 desc2 10 T 121 cust2 desc2 -10 F price decrease PD121 cust2 desc2 10 A new customer NC234 cust3 desc4 -60 F 234 cust3 desc4 60 T price increase PI235 cust3 desc5 30 A 235 cust4 desc6 -50 F 235 cust4 desc6 70 T price increase PI You want this output?GROUP AMOUNTNC 10PI 20PD 0SR -45SA 45 If that is the case, can you post sample data in a consumable format (create table & insert statements). And explain the logic for transforming the data into the expected result set (I.E what is a changed amount?). Here are some other links that can be helpful for posting you data or asking future questions:http://www.sqlservercentral.com/articles/Best+Practices/61537/http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx |
|
|
|
|
|