项目SQL存储过程学习

来源:互联网 发布:淘宝闲鱼客户端 编辑:程序博客网 时间:2024/06/06 03:49

 验证用户是否存在的存储教程

select * from gz where passowrd=@passowrd and UserName=@userName

if(@@RowCount=0)

return -1

else

return 1

 

查找密码大于4的记录

select * from Users where len(password)>4

 

截取字符串:

select * from Users where substring(password='123' 

 

转换字符:

select id,cast(@substring as int) from aa

 

四舍五入为指定小数位数:

select id,round(cast(isnull(buyshore,0) as float)/buyshore*100,2) as schedule

 

case函数的使用

set @returnDescription='方案已被'+case @QuashStatus when 1 then '用户' when 2 then '系统' else'' end+"撤单"

 

charindex来匹配文字列和字符串返回一个非零的整数

if(@OpenUser='' ) and (charindex(','+cast(@LotteryID as varchar)+',', ','+@UserLotteryList+',')<=0)

dateadd函数的使用

return dateadd(minute,@SystemEndAheadMinute*-1,@EndTime)

 

 自增ID的获取:

insert操作以后,

select @NewID=SCOPE_IDENTITY()

 

 

txtptr函数的使用:以 varbinary 格式返回对应于 text、ntext 或 image 列的文本指针值

select @ptrdescription1=txtptr(description) from  T_ChaseTasks

 

datediff是计算两个时间间的间隔差

set @FreeTime=Datediff(minute,@FreezeLoginTime,GetDate())

 

 datepart的使用

set @date=cast(datepart(yy,@dateStart) as varchar(10))

 

exec sql_executesql 学习

exec sql_excutesql @Cmd,N'@value image',@value

 

floor传回小于或等于指定数值运算式的的最大整数

set @Reslult=@Diviend/@Divisor    if(@Result=floor(@Result))

原创粉丝点击