sqlServer问题记录

1.sql 2008 无法绑定由多个部分绑定的标示符

连接中的多个表中存在同名字段,通过设置别名访问即可

 2.远程无法连接到sqlserver

计算机管理->服务与应用程序->SQL Server配置管理器->SQL Server服务,打开SQL Server和SQL Server Browser

 3.判断字段为空

isnull(name,0)--如果为空则置位0

 4.获取当月第一天和最后一天的时间

declare @startTime datetime
declare @endTime datetime
set @startTime=dateadd(d,-day(getdate())+1,getdate()) --GETDATE()--获取系统当前时间
set @endTime=dateadd(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))
select convert(char(10),@startTime,120) as Date
select convert(char(10),@endTime,120) as Date

 5.判断字段非空

字段 is not null

 6.判断信息是否存在

if exists( select * from table where id='id' )
  Begin
    print '1'
  End
else
  Begin
     print '0'
  End

 7.退出存储过程

select * from table
return

 8.不适用拼接字符串执行的方式,根据参数执行不同的where子句

1.使用where (addDate = @addDate or @addDate is null)
2.使用case then

 9.从同一张表根据不同条件进行查询,拼接成新的表将查询结果显示为新增的字段

--假设有表A
--三个结果集分别显示数据[id,a]、[id,b]、[id,c]
--需要的结果为id,a,b,c
--此处由于根据不同的条件查询出来的id不一致,所以不能直接使用左、右连接,
--不然会丢失内容,那这里就考虑使用全连接的方式来完成
--但由于这里的id只需要显示一次,且不能显示为空的情况
--所以需要对id进行处理
select isnull(isnull(a.id,b.id),c.id) id,a.a,b.b,c.c
from
(select id,a as a from A)a
full join
(select id,a as b from A)b
on a.id=b.id
full join
(select id,a as c from A)c
on b.id=c.id

10.sqlserver 不允许保存更改 您所做的更改

工具->选项->组织保存要求重新创建表的更改

 


 11.降级

数据库->任务->生成脚本->设置脚本编写选项->高级->选择需要的版本

 

posted @ 2018-03-07 08:58  Hey,Coder!  阅读(187)  评论(0编辑  收藏  举报