首页 > 数据库 >sqlserver执行语句返回刚刚插入的ID

sqlserver执行语句返回刚刚插入的ID

时间:2022-10-31 17:55:23浏览次数:41  
标签:语句 convert 101 varchar sqlserver datetime 100 LimiteBuy ID

 sqlserver执行语句返回刚刚插入的ID

 

#region----新增一条活动表数据----
        /// <summary>
        /// 新增一条活动表数据
        /// </summary>
        /// <param name="appointmentEntity"></param>
        /// <returns></returns>
        public int InsertAppointment(Appointment appointmentEntity)
        {
            string sql = @"
                insert into Appointment 
                (
                BID,Title,PicUrl,ErpStoreID,Phone,
                AddressInfo,AddressMap,ApDesc,ApUseDesc,BeginDate,
                EndDate,Interval,AdvanceCycDay,LimiteBuy,LimiteBuy_Total,
                LimiteBuy_Day,LimiteBuy_Trade,IsNeedUserPhone,IsValPhone,CusInputeInfo,
                InterValType,InterValSize,Status,CreateDate,UpdateDate
                )
                values
                (
                @BID,@Title,@PicUrl,@ErpStoreID,@Phone,
                @AddressInfo,@AddressMap,@ApDesc,@ApUseDesc,@BeginDate,
                @EndDate,@Interval,@AdvanceCycDay,@LimiteBuy,@LimiteBuy_Total,
                @LimiteBuy_Day,@LimiteBuy_Trade,@IsNeedUserPhone,@IsValPhone,@CusInputeInfo,
                @InterValType,@InterValSize,@Status,@CreateDate,@UpdateDate
                )
                SELECT  @@IDENTITY  as  'ApID'
                    ";
            //ExecuteScalar,返回刚刚插入的ID的值
            var insertResultId = _dbBase.ExecuteScalar(sql, appointmentEntity);
            int insertId = Convert.ToInt32(insertResultId);
            return insertId;
        }
        #endregion

 

---系统划分,新增一条规格
insert into ApInterSku 
(
ApID,BID,InterValType,InterValSize,
BeginDate,EndDate,
AdvanceDate,
CreateDate,UpdateDate,
SysBeginDate,SysEndDate
)
values
(
666,957,0,1,
convert(varchar(100),convert(datetime,'12:00',101),24),convert(varchar(100),convert(datetime,'13:00',101),24),
convert(varchar(100),convert(datetime,null,101),23),
getdate(),null,
convert(varchar(100),convert(datetime,'08:00',101),24),convert(varchar(100),convert(datetime,'18:00',101),24)
)
--返回刚刚插入的主键ID的数据
SELECT  AvSkuID,BeginDate,EndDate from ApInterSku where AvSkuID=@@IDENTITY

 

搜索

复制

标签:语句,convert,101,varchar,sqlserver,datetime,100,LimiteBuy,ID
From: https://www.cnblogs.com/jankie1122/p/11109335.html

相关文章

  • sqlserver 分区函数去重复排序
     sqlserver分区函数去重复排序--获取,FlowID去重复的,按时间排序的,前一行select*from(select*,row_number()over(partitionbyFlowIDorderbyConfirmDat......
  • not present in DVTPlugInCompatibilityUUIDs
    2022-10-3117:24:38.827xcodebuild[43498:351656][MT]PluginLoading:Requiredplug-incompatibilityUUID57505DC8-7C02-42C5-9C44-13FD1CB92B41forplug......
  • IDEA配置tomcat虚拟路径
    myeclipse配置虚拟路径的话需要去改tomcat配置文件,但是idea比这方便许多,直接配置即可,配置方式如下:在下图中选中你想用来作为虚拟路径的那个文件夹我这里已经选好了,是qyBlog......
  • sqlserver 分页嵌套Order by
     sqlserver分页嵌套Orderby  //筛选varwhereParts=newList<string>();whereParts.Add("p.BID=@BID");......
  • Installation SlideV
    StarterTemplate#SlidevrequiresNode.js>=14.0Thebestwaytogetstartedisusingourofficialstartertemplate.WithNPM:$npminitslidev@latestWithYa......
  • WPF DataGrid 按 Enter 移动到下一个单元格 开启编辑
    MoveFocustoNextCellonEnterKeyPressinWPFDataGrid?BegineditmodeonkeypresswithDataGridTemplateColumnWPF中DataGrid按Enter移动到下一个单元格开启......
  • sqlserver 存储过程 where Id in 传参
     sqlserver存储过程whereIdin传参----更新多条数据,不传参updateStudentssetStuName='12348888'whereStuIDin('1','2') ----更新多条数据,传参DECLARE......
  • sqlserver 根据多个字段查询重复数据
     sqlserver根据多个字段查询重复数据如:表a abcdef 121231121231121232121232表中每个字段只要有一个不一样就算不重复 selecta,b,......
  • C#和sql结合,返回刚新增的ID主键的值
     C#和sql结合,返回刚新增的ID主键的值#region----新增一条预约活动表数据----///<summary>///新增一条预约活动表数据///</summary>......
  • sqlserver 关于 case when is null 的查询
    sqlserver关于casewhenisnull的查询select*fromApInterSkuInfowhereBeginValue=convert(varchar(100),convert(datetime,'2017-12-0923:59:59.8',101),23)......