简体   繁体   English

创建存储过程SQL

[英]Creating a stored procedure SQL

I have this codec and I need to make it into a stored procedure. 我有此编解码器,需要将其放入存储过程中。 I know the basics of it and am still new to the concept so I apologize for asking but once I see my error I can take it into a good learning experience if anyone can help solve my problem. 我知道它的基本知识,但仍然是这个概念的新手,因此我很抱歉提出这个问题,但是一旦发现错误,如果有人可以帮助解决我的问题,我就可以将其带入良好的学习体验中。 This is the codec I have. 这是我的编解码器。

  CREATE PROC spGetCancelDate

  AS

  Begin

     SELECT  c.program_id, d.dealer_code,b.last_name As DealerName, a.account_no, a.vin, ((e.last_name)+','+(e.first_name)) As Name, 
a.cancel_refund_date, a.purchase_date,a.miles, a.duration,a.sale_price,a.number_of_payments,  a.sales_tax, a.downpayment

from tDealer d 

Join tContact b ON d.contact_id = b.contact_id 

Join tContract a On d.dealer_id = a.dealer_id 

Join tCompany c ON d.company_id= c.company_id

Join tContact E On e.contact_id = a.contact_id

Where c.program_id = @program And a.cancel_refund_date Between @BeginDate And @Endate

End

It's difficult to test a stored procedure and syntax ect when you have nothing to run it off. 当您无须运行存储过程和语法时,很难对其进行测试。

Read through the following link and learn about how they are made. 通读以下链接,了解其制作方法。

Once you have created the proc because you aren't creating/updating anything you can have a play around until it works worry free. 一旦创建了proc(因为您没有创建/更新任何内容),您就可以尝试一下,直到它正常运行为止。

Basically a stored procedure is a saved script for either selecting, updating, inserting or deleting records. 基本上,存储过程是用于选择,更新,插入或删除记录的已保存脚本。 Very useful if you are going to execute the same SQL over and over again. 如果要一遍又一遍地执行相同的SQL,这将非常有用。

Creating: http://dev.mysql.com/doc/refman/5.0/en/create-procedure.html 创建: http : //dev.mysql.com/doc/refman/5.0/en/create-procedure.html

Altering: http://dev.mysql.com/doc/refman/5.0/en/alter-procedure.html 变更: http : //dev.mysql.com/doc/refman/5.0/en/alter-procedure.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM