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 |
|
jtsiller
Starting Member
4 Posts |
Posted - 2006-06-28 : 22:34:16
|
| I'm using a subform to display data stored in SQL Server. The dilema I'm having is the scrollbar is getting quite small, or a lot longer to scroll to the end. I have eight columns that all store a currency value. I decided to utilize one drop down and one currency column to replace the others. Even though it works better, I'm running into other problems. Pulling calculations on the form is much more complicated; I can no longer use sum([value name]) in the application. The one currency column hosts all currency values and the only distinguishing difference is the type drop down.How can I transfer the amount to the proper column in SQL Server based off the type column? Is this the best approach? Is there another solution? If so, please point me in the right direction. |
|
|
Lumbago
Norsk Yak Master
3271 Posts |
Posted - 2006-06-29 : 03:35:00
|
| I'm seriusly confused...I don't think I understood anything whatsoever of your problem...is it possible that you rephrase? Maybe give some examples?--Lumbago"Real programmers don't document, if it was hard to write it should be hard to understand" |
 |
|
|
jtsiller
Starting Member
4 Posts |
Posted - 2006-06-29 : 08:28:02
|
| RefundAmount money columnPaymentAmount money columnAdjustmentAmount money columnPrepayAmount money columnRefundTMID Nvarchar columnPaymentTMID Nvarchar columnAdjustmentTMID Nvarchar columnPrepayTMID Nvarchar columnAs you can see these are similar columns. I'm now using Amount money columnAmountTMID columnI'm trying to find the best way to return calculated values for each group, for a specific batch on the front end. Is there an easy way of doing this? |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-06-29 : 08:59:58
|
Define batch and group, please. If possible, post some sample data here together with expected output based on the provided sample data.Help us help you.Is it this you want to accomplish?SELECT 'Refund' Batch RefundTMID TMID, SUM(RefundAmount) AmountFROM MyTableGROUP BY RefundTMIDUNION ALLSELECT 'Payment' PaymentTMID, SUM(PaymentAmount)FROM MyTableGROUP BY PaymentTMIDUNION ALLSELECT 'Adjustment' AdjustmentTMID, SUM(AdjustmentAmount)FROM MyTableGROUP BY AdjustmentTMIDUNION ALLSELECT 'Prepay' PrepayTMID, SUM(PrepayAmount)FROM MyTableGROUP BY PrepayTMID Or a cross-tab/pivot like this?SELECT z.TMID, ISNULL(SUM(Re.RefundAmount), 0) 'Refund', ISNULL(SUM(Pa.PaymentAmount), 0) 'Payment', ISNULL(SUM(Ad.AdjustmentAmount), 0) 'Adjustment', ISNULL(SUM(Pr.PrepayAmount), 0) 'Prepay'FROM ( SELECT RefundTMID TMID FROM MyTable UNION SELECT PaymentTMID FROM MyTable UNION SELECT AdjustmentTMID FROM MyTable UNION SELECT PrepayTMID FROM MyTable ) zLEFT JOIN MyTable Re ON z.TMID = Re.RefundTMIDLEFT JOIN MyTable Pa ON z.TMID = Pa.PaymentTMIDLEFT JOIN MyTable Ad ON z.TMID = Ad.AdjustmentTMIDLEFT JOIN MyTable Pr ON z.TMID = Pr.PrepayTMIDGROUP BY z.TMIDORDER BY z.TMID Peter LarssonHelsingborg, Sweden |
 |
|
|
jtsiller
Starting Member
4 Posts |
Posted - 2006-06-29 : 09:33:19
|
| Thank you for helping.A batch is basically a unique key. Within the batch I can have multiple refunds, prepays, payments, adjustments, etc..... I'm defining refunds, prepays, payments, and adjustments as the grouped portions. I'm only wanting to find the totals of the groups per a unique batch.Here is a stored procedure I have.CREATE PROCEDURE dbo.procCountTotals@BMIBatch Nvarchar(8),@TotalRefund money OUTPUT,@TotalPrepay money OUTPUT,@TotalAdjustment money OUTPUT,@TotalPayment money OUTPUTASSELECT @TotalRefund = ISNULL(SUM(Amount), 0)FROM dbo.RefundsWHERE (Type = N'Refund') AND (Batch = @Batch)SELECT @TotalPrepay = ISNULL(SUM(Amount), 0)FROM dbo.RefundsWHERE ((Type = N'Reverse Prepay') OR (Type = N'Apply Prepay') ) AND (BMIBatch = @Batch)SELECT @TotalAdjustment = ISNULL(SUM(Amount), 0)FROM dbo.RefundsWHERE (Type = N'Adjustment') AND (BMIBatch = @Batch)SELECT @TotalPayment = ISNULL(SUM(Amount), 0)FROM dbo.RefundsWHERE (Type = N'JV') AND (BMIBatch = @Batch)Select @TotalRefund, @TotalPrepay, @TotalAdjustment, @TotalPaymentGOThe stored procedure works beautifully, but it gets a little clumbsy programming the front end. This is why I was hoping to transfer information from the amount column to the desired group(refund, prepay, adjustment, payment), based on the type that was selected. This would allow me to skip having to call a procedure.Example in vba I could use something likeSelect Case Me.cboType Case "Refund" Me.Amount = Me.Refund Case "Prepay" Me.Amount = Me.Prepay etc..............Doing this would allow me to calculate the columns on the front end without calling something from the backend. I'm hoping to do something similar on the back end. How can I copy the amount to the desired refund, prepay, adjustment, payment based off the users type selection.I hope this makes since. I do appreciate the help. |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2006-06-29 : 14:47:43
|
| Then why don't you help us helping you with posting the complete DDL here?How are we supposed to help you if we don't get all the information the first place, such as batch column?1. Post complete DDL here2. Post some sample data here3. Post the expected output here based on the provided sample dataPeter LarssonHelsingborg, Sweden |
 |
|
|
|
|
|
|
|