易截截图软件、单文件、免安装、纯绿色、仅160KB

在SQL Server数据库中拆分字符串函数

SQL Server数据库中拆分字符串函数的具体方法:
以下为引用的内容:
  CREATE  FUNCTION uf_StrSplit '1.1.2.50','.'
  (@origStr varchar(7000),  --待拆分的字符串
  @markStr varchar(100))  --拆分标记,如','
  RETURNS @splittable table
  (
   str_id  varchar(4000) NOT NULL, --编号ID
   string  varchar(2000) NOT NULL --拆分后的字符串
  )
  AS
  BEGIN
  declare @strlen int,@postion int,@start int,@sublen int,
  @TEMPstr varchar(200),@TEMPid int
  SELECT @strlen=LEN(@origStr),@start=1,@sublen=0,@postion=1,
  @TEMPstr='',@TEMPid=0
  if(RIGHT(@origStr,1)<>@markStr )
  begin
  set @origStr = @origStr + @markStr
  end
  WHILE((@postion<=@strlen) and (@postion !=0))
  BEGIN
  IF(CHARINDEX(@markStr,@origStr,@postion)!=0)
  BEGIN
  SET @sublen=CHARINDEX(@markStr,@origStr,@postion)-@postion;
  END
  ELSE
  BEGIN
  SET @sublen=@strlen-@postion+1;
  END
  IF(@postion<=@strlen)
  BEGIN
  SET @TEMPid=@TEMPid+1;
  SET @TEMPstr=SUBSTRING(@origStr,@postion,@sublen);
  INSERT INTO @splittable(str_id,string)
  values(@TEMPid,@TEMPstr)
  IF(CHARINDEX(@markStr,@origStr,@postion)!=0)
  BEGIN
  SET @postion=CHARINDEX(@markStr,@origStr,@postion)+1
  END
  ELSE
  BEGIN
  SET @postion=@postion+1
  END
  END
  END
  RETURN
  END
例如:select * from uf_StrSplit('1,1,2,50',',')
输出结果:
以下为引用的内容:
  str_id   string
  1       1
  2       1
  3       2
  4      50
------分隔线----------------------------


相关文档:

动态SQL基本语法

1 :普通SQL语句可以用exec执行
Select * from tableName
exec('select * from tableName')
exec sp_executesql N'select * from tableName' -- 请注意字符串前一定要加N
2:字段名,表名,数据库名之类作为变量时,必须用动态SQL
declare @fname varchar(20)
set @fname = 'FiledName'
Select @fname from tab ......

SQL Server取系统当前时间

getdate //获得系统当前日期
datepart //获取日期指定部分(年月日时分表)
getdate()函数:取得系统当前的日期和时间。返回值为datetime类型的。
用法:getdate()
例子:
select getdate() as dte,dateadd(day,-1,getdate()) as nowdat
输出结果:
dte nowdat
--------------------------- ----------------- ......

sql 里的 update 实现联合表更新

 1.update a set a.nickname=b.nickname from tab1 a,tab2 b where a.username=b.username
2.Update student_score set
student_score.level=level_about.level from
level_about where student.score
between level_about.start_score and level_about.end_score ......

SQL数据库:因为文件组 'PRIMARY' 已满的解决方法

 1.检查你是否限制了文件增长:  
       企业管理器--右键你的数据库--属性--数据文件--看看有没有设置文件的最大值  
   
   2.检查你的磁盘分区格式,如果不是NTFS分区,则会有限制,将磁盘分区格式改成NTFS  
 &n ......

sql语句 访问不同数据库服务器中的数据库对象的方法

 在我们做数据库程序开发的时候,经常会遇到这种情况:需要将一个数据库服务器中的数据导入到另一个数据库服务器的表中。通常我们会使用这种方法:先把一个数据库中的数据取出来放到某出,然后再把这些数据一条条插入到目的数据库中,这种方法效率较低,写起程序来也很繁琐,容易出错。另外一种方法是使用bcp或BULK IN ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号