我想在存储过程中使用字段modifieddatetime调用get date函数 [英] I want to call get date function with field modifieddatetime in a stored procedure
问题描述
这是我创建的存储过程
更改程序[dbo]。[UpdateInDegrees]
- 在此处添加存储过程的参数
@ID int输出,@ Name nvarchar(100),@ Code nvarchar(10)
AS
BEGIN
- - 添加SET NOCOUNT ON以防止来自
的额外结果集 - 干扰SELECT语句。
声明@ModifiedDateTime日期时间
SET NOCOUNT ON;
设置@ModifiedDateTime = getdate()
- 在此处插入程序语句
更新度数设置名称=上(@Name),代码=上(@Code)其中ID = @ ID
结束
这是我调用此存储过程的函数
public void UpdateInDegrees(TextBox _txtdgname,TextBox _txtdgcode,Label _lbldgID)
{
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText =UpdateInDegrees;
cm.Parameters.AddWithValue(@ Name,_txtdgname.Text);
cm.Parameters.AddWithValue(@ Code,_ txtdgcode.Text);
cm.Parameters.AddWithValue(@ ID,_lbldgID.Text);
cm.ExecuteNonQuery();
}
我尝试过:
ALTER PROCEDURE [dbo]。[UpdateInDegrees]
- 在这里添加存储过程的参数
@ID int output,@名称nvarchar(100),@ Code nvarchar(10)
AS
BEGIN
- 添加SET NOCOUNT ON以防止额外的结果集来自
- 干扰SELECT语句。
声明@ModifiedDateTime日期时间
SET NOCOUNT ON; < br $>
设置@ModifiedDateTime = getdate()
- 在此处插入程序语句
更新度数设置名称= Upper(@Name),Code = Upper(@Code)其中ID = @ ID
END
我假设你想要使用修改日期为您的记录加时间戳?
如果是这样,请使用您设置的@ ModifiedDateTime值,或直接执行:
更新度 SET 名称=上限( @ Name ),Code = Upper( @ Code ),ModifiedAt = GETDATE() WHERE ID = @ ID
this is a stored procedure which i created
ALTER PROCEDURE [dbo].[UpdateInDegrees]
-- Add the parameters for the stored procedure here
@ID int output,@Name nvarchar(100),@Code nvarchar(10)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
Declare @ModifiedDateTime Datetime
SET NOCOUNT ON;
Set @ModifiedDateTime = getdate()
-- Insert statements for procedure here
Update Degrees set Name=Upper(@Name),Code=Upper(@Code) where ID=@ID
END
this is a function where i call this stored procedure
public void UpdateInDegrees(TextBox _txtdgname, TextBox _txtdgcode, Label _lbldgID)
{
cm = new SqlCommand();
cm.Connection = cn;
cm.CommandType = CommandType.StoredProcedure;
cm.CommandText = "UpdateInDegrees";
cm.Parameters.AddWithValue("@Name", _txtdgname.Text);
cm.Parameters.AddWithValue("@Code", _txtdgcode.Text);
cm.Parameters.AddWithValue("@ID", _lbldgID.Text);
cm.ExecuteNonQuery();
}
What I have tried:
ALTER PROCEDURE [dbo].[UpdateInDegrees]
-- Add the parameters for the stored procedure here
@ID int output,@Name nvarchar(100),@Code nvarchar(10)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
Declare @ModifiedDateTime Datetime
SET NOCOUNT ON;
Set @ModifiedDateTime = getdate()
-- Insert statements for procedure here
Update Degrees set Name=Upper(@Name),Code=Upper(@Code) where ID=@ID
END
I'm assuming you want to timestamp your records with a modification date?
If so, either use the @ ModifiedDateTime value you set, or do it directly:
UPDATE Degrees SET Name=Upper(@Name),Code=Upper(@Code), ModifiedAt = GETDATE() WHERE ID=@ID
这篇关于我想在存储过程中使用字段modifieddatetime调用get date函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!