尝试通过检查条件使用单个插入语句插入不同的结果集

发布于 2024-11-24 07:38:28 字数 1858 浏览 3 评论 0原文

我有一个带有四个文本框、两个下拉列表和一个“保存”按钮

文本框的 winform,就像这些

  • Startdate 文本框,其中在文本框中输入了值 2011-03-02 (yyyy-mm-dd)

  • 在文本框中输入值的结束日期文本框 2013-09-04 (yyyy-mm-dd)

  • 截止日期文本框,在该文本框中输入的值为 (2011-03-15) (15 2011 年 3 月)

  • 到期金额文本框,在该文本框中输入的值为 120.00。

  • 付款选项下拉列表,值为 12 个月现金、24 个月 现金

  • 付费选项下拉列表,包含每年、每月的值

我有一个表格,

       paymentschedule 
     columns:         paymentscheduleid
                      datetobepaid
                      amountdue
                      paymentoption 

,当您单击“保存”按钮时,

这些值将保存在如下表中,设置这将是结果集,如果“付费选项”是每月,结果集如下(付费选项是每月)

  paymentscheduleid      datetobepaid      amountdue      paymentoption

       1                   2011-04-15        120.00        12 months cash
       2                   2011-05-15        120.00        12 months cash
       3                   2011-06-15        120.00        12 months cash
       4                   2011-07-15        120.00        12 months cash
       -                       -              -                  -
       -                       -              -                  -
       -                       -              -                  -
       20                 2013-08-15        120.00         12 months cash

如果付费选项是每年,那么结果集将是这样的(付费选项是每年)

       paymentscheduleid      datetobepaid      amountdue      paymentoption

             1                  2011-04-15        120.00         12 month cash
             2                  2012-04-15        120.00         12 months cash
             3                  2013-04-15        120.00         12 months cash

datetobpaid 取决于开始日期和到期中输入的值日文本框

是否可以使用 mysql 和 c# 使用单个 insertstatement

任何人都可以帮助解决这个问题

,非常感谢......

i have a winform with four textboxes and two dropdown lists and a Save button

textboxes are like these

  • Startdate textbox with value entered in the textbox 2011-03-02
    (yyyy-mm-dd)

  • Enddate textbox with value entered in textbox 2013-09-04 (yyyy-mm-dd)

  • due day text box, value entered in that textbox is (2011-03-15) (15
    th of march 2011)

  • amonut due textbox with value entered in that textbox is 120.00.

  • paymentoption dropdownlist with values 12 months cash, 24 months
    cash

  • paid option dropdownlist with values yearly , monthly

and i have a table

       paymentschedule 
     columns:         paymentscheduleid
                      datetobepaid
                      amountdue
                      paymentoption 

when you click on save button the values are saved in table like below set

this will be the resultset if "paid option" is monthly and the result set is given below (paid option is monthly)

  paymentscheduleid      datetobepaid      amountdue      paymentoption

       1                   2011-04-15        120.00        12 months cash
       2                   2011-05-15        120.00        12 months cash
       3                   2011-06-15        120.00        12 months cash
       4                   2011-07-15        120.00        12 months cash
       -                       -              -                  -
       -                       -              -                  -
       -                       -              -                  -
       20                 2013-08-15        120.00         12 months cash

if paid option is yearly then the result set will be like this (paid option is yearly)

       paymentscheduleid      datetobepaid      amountdue      paymentoption

             1                  2011-04-15        120.00         12 month cash
             2                  2012-04-15        120.00         12 months cash
             3                  2013-04-15        120.00         12 months cash

the datetobpaid depends on startdate and the value entered in the due day textbox

is it possible to use single insertstatement using mysql and c#

would any one help on this problem

many thanks......

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

本宫微胖 2024-12-01 07:38:28

这是在 MS Sql 上完美运行的,您可以根据需要将其更改为 Mysql:

declare @DueDate Datetime
declare @EndDate Datetime

declare @PaidOption varchar(10)
set @PaidOption='Monthly'

set @DueDate='2011-03-15'
set @EndDate='2013-09-04'


if @PaidOption='Monthly' -- for monthly
Begin
set @DueDate=DATEADD(month,+1,@DueDate)
WHILE @DueDate<@EndDate
BEGIN  
--insert statement use @duedate for datetobepaid and other values are as you input
  set @DueDate=DATEADD(month,+1,@DueDate)

END
End
Else -- for yearly
Begin
set @DueDate=DATEADD(Year,+1,@DueDate)
WHILE @DueDate<@EndDate
BEGIN  
--insert statement use @duedate for datetobepaid and other values are as you input
  set @DueDate=DATEADD(year,+1,@DueDate)

END
End

这里 Paidoption 和其他字段是静态设置的。尽管您可以将其用作输入参数

希望这可以解决您的问题

This is perfectly run on MS Sql you can change it to Mysql as you need:

declare @DueDate Datetime
declare @EndDate Datetime

declare @PaidOption varchar(10)
set @PaidOption='Monthly'

set @DueDate='2011-03-15'
set @EndDate='2013-09-04'


if @PaidOption='Monthly' -- for monthly
Begin
set @DueDate=DATEADD(month,+1,@DueDate)
WHILE @DueDate<@EndDate
BEGIN  
--insert statement use @duedate for datetobepaid and other values are as you input
  set @DueDate=DATEADD(month,+1,@DueDate)

END
End
Else -- for yearly
Begin
set @DueDate=DATEADD(Year,+1,@DueDate)
WHILE @DueDate<@EndDate
BEGIN  
--insert statement use @duedate for datetobepaid and other values are as you input
  set @DueDate=DATEADD(year,+1,@DueDate)

END
End

here Paidoption and other fields are set statically .Although you can use it as input parameters

Hope This May Solve your problem

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文