增减时间(正负数):DateTime dt = Convert.ToDateTime(Convert.ToString(time)).AddDays(-1);
添加自动增长字段:select * ,identity(int,1,1)as ddd into #mytable from mytable
获取日期部分值:select datename(month,getdate())
随机值:rtrim(100000+cast(900000*rand(checksum(newid())) as int))
过滤条件为空查全部:where a.date = case when @date = '' then a.date else @date end
OriginalValue:指示发生任何更改前记录中已经存在的 Field 的值。 UnderlyingValue:指示数据库中 Field 对象的当前值。
用于between and 有不同的结果:SELECT replace(replace(replace(2007年10月17日,'年','-'),'月','-'),'日','') -----> 2007-10-17 (字符串)SELECT Convert(datetime,replace(replace(replace(2007年10月17日,'年','-'),'月','-'),'日','')) -----> 2007-10-17 (时间)
创建数据库 SqlConnection con = new SqlConnection("server = .; uid = sa ; pwd = 密码 ; database = tempdb"); con.Open(); SqlCommand cmd = new SqlCommand("create database mydb", con); cmd.ExecuteNonQuery(); con.ChangeDatabase("mydb"); cmd = new SqlCommand("create table information(studentid char(10),name char(10),scoure char(10))", con); cmd.ExecuteNonQuery(); MessageBox.Show("数据库[mydb]建立成功!");
创建---添加--查询--删除create table #A(amount decimal(6,2), paidamount decimal(6,2), balance decimal(6,2))
insert into #A (amount ,paidamount,balance) select sum(amount)c_amount,sum(paidamount)c_paidamount,sum(balance)c_balance from yhaplist
select * from #A
drop table #A
添加列--列赋值--不同表不同条件赋值--删除列alter table GwByHCurrentQty add tempcol varchar(128)
update GwByHCurrentQty set tempcol = (select gwbymeasureunit.name from yhwlshopproduct left join gwbymeasureunit on gwbymeasureunit.id = yhwlshopproduct.measureunitid where yhwlshopproduct.number = GwByHCurrentQty.num)
update GwByHCurrentQty set quantity = case when (select count from #all where number = GwByHCurrentQty.num and name = GwByHCurrentQty.tempcol) is null then 0 else (select count from #all where number = GwByHCurrentQty.num and name = GwByHCurrentQty.tempcol) end where pihao = (select top 1 pihao from GwByHCurrentQty aa where aa.num = GwByHCurrentQty.num order by pihao desc)
ALTER TABLE GwByHCurrentQty DROP column tempcol
报警: 判断 是否一年左右,有没有到期限,有没有在alarm表中 select licenseID from licenseInformation where ('"+today+"' between (benkDate+362) and (benkDate+368)) and (benkDate < limitDate)and licenseInformation.licenseID not in (select LicID from Alarm) 不在,弹出对话框提示,并添加到alarm表中,修改备用时间。 insert into Alarm(LicID,DaTi) values ('" + licID + "','" + DateTime.Now + "') update licenseInformation set benkDate = (benkDate + 365) where licenseID = '" + licID + "'"
处理存在的,判断是否至今天已经超过6天了,若超过就删除 delete from Alarm where (dati+6)< '"+today+"'