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

SQL 中将一个表转化成建表语句的存储过程

SET QUOTED_IDENTIFIER ON
GO
SET ANSI_NULLS ON
GO
CREATE proc pGetInsertSQL (@TableName varchar(256))
as
begin
    set nocount on
    declare @sqlstr varchar(4000)
    declare @sqlstr1 varchar(4000)
    declare @sqlstr2 varchar(4000)
    select @sqlstr='select ''insert '+@tablename
    select @sqlstr1=''
    select @sqlstr2=' ('
    select @sqlstr1= ' values ( ''+'
    select @sqlstr1=@sqlstr1+col+'+'',''+' ,@sqlstr2=@sqlstr2+name +',' from (select case
--    when a.xtype =173 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.length*2+2)+'),'+a.name +')'+' end'
    when a.xtype =104 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(1),'+a.name +')'+' end'
    when a.xtype =175 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''''''','''''''''''')' + '+'''''''''+' end'
    when a.xtype =61  then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'convert(varchar(23),'+a.name +',121)'+ '+'''''''''+' end'
    when a.xtype =106 then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar('+convert(varchar(4),a.xprec+2)+'),'+a.name +')'+' end'
    when a.xtype =62  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(23),'+a.name +',2)'+' end'
    when a.xtype =56  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(11),'+a.name +')'+' end'
    when a.xtype =60  then 'case when '+a.name+' is null then ''NULL'' else '+'convert(varchar(22),'+a.name +')'+' end'
    when a.xtype =239 then 'case when '+a.name+' is null then ''NULL'' else '+'''''''''+'+'replace('+a.name+','''


相关文档:

今天装了Oracle SQL developer

下载后解压缩就能直接使用了,但是是中文的,字体显示的不是很好,于是找到了换英文的办法:
由于1.5包含了多语言界面的支持,但是它是通过JVM来辨认系统语言的,所以当你的系统语言为中文的时候,它会使用中文界面。不过它的中文翻译并不完整,加上默认界面字体太小,使用中文会看着非常难受。如果想使用英文界面,需要修 ......

SQL SERVER获取表的空间分布情况

/********************************
功能:获取表的空间分布情况
**********************************/
if not exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[tablespaceinfo]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
create table  tablespaceinfo      ......

用sql获取某字符串中的数字部分

create function dbo.F_Get_No
(
 @No varchar(100)
)
RETURNS bigint
AS
BEGIN
 WHILE PATINDEX('%[^0-9]%',@No)>0
 BEGIN
  SET @No=STUFF(@No,PATINDEX('%[^0-9]%',@No),1,'') --删掉一个非数字的字符,循环结束,剩余的为数字部分
 END
 RETURN CONVERT(bigint,@No ......

尽量避免在SQL语句中使用OR

----start
    在SQL语句中应该尽量避免使用OR,因为这样做会影响SQL语句的性能。考虑下面的情况:
CREATE TABLE USER
(
NAME VARCHAR(20) NOT NULL,---姓名
BIRTHDAY DATE---生日
); 
现在有这样一个问题:让你查找一下生日是1949-10-1(共和国同龄人)或1978-12-18(十一届三中全会召开时间) ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号