如何将查询转换为存储过程? [英] How to convert Query into Stored Procedure ?

查看:96
本文介绍了如何将查询转换为存储过程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将以下查询转换为存储过程(MS Sql Server)?

How to convert the below Query into Stored Procedure(MS Sql Server) ?

select rating,trendvalue
from rptslastats where sla='" + dsReportName.Tables[0].Rows[p][0].ToString() + "'
and to_char(asondate,'mon yy')=to_char(to_date('" + asondate.ToShortDateString() + "','mm/dd/yyyy'),'mon yy')

推荐答案

create procedure MyProc
as
  select rating,trendvalue
  from rptslastats 
  where sla='" + dsReportName.Tables[0].Rows[p][0].ToString() + "'and to_char(asondate,'mon yy')=to_char(to_date('" + asondate.ToShortDateString() + "','mm/dd/yyyy'),'mon yy')


存储过程:

stored procedure:
create procedure procedureName
(
@sla varchar(100) ,
@leftparam varchar(100),
@rightparam varchar(100)

)
as
begin

select rating,trendvalue from rptslastats
 where sla= @sla and  @leftparam = @rightparam 
end 





你必须指定值为



and you have to assign values as

@sla                      -> '" + dsReportName.Tables[0].Rows[p][0].ToString() + "'
 @leftparam varchar(100)  -> to_char(asondate,'mon yy')               
@rightparam varchar(100)  ->  to_char(to_date('" + asondate.ToShortDateString() + "','mm/dd/yyyy'),'mon yy')   





希望它工作正常......



hope it works fine...


这篇关于如何将查询转换为存储过程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆