**找不到了.拿來後修改了ntext和text存放html中有'會出現錯誤的情況.
create procedure sp_findinsertinto
@tablename sysname
as
declare @column varchar(1000)
declare @columndata varchar(1000)
declare @sql varchar(4000)
declare @xtype tinyint
declare @name sysname
declare @objectid int
declare @objectname sysname
declare @ident int
set nocount on
set @objectid=object_id(@tablename)
if @objectid is null -- 判斷物件是否存 在
begin
print 'the object not exists'
return
end
set @objectname=object_name(@objectid)
if @objectname is null or charindex (@objectname,@tablename)=0 --此判斷不嚴密
begin
print 'object not in current database'
return
end
if objectproperty(@objectid,'istable') <> 1 -- 判斷物件是否是table
begin
print 'the object is not table'
return
end
select @ident=status&0x80 from syscolumns where id=@objectid and status&0x80=0x80
if @ident is not null
print 'set identity_insert '+@tablename+' on'
declare syscolumns_cursor cursor
for select c.name,c.xtype from syscolumns c
where c.id=@objectid
order by c.colid
open syscolumns_cursor
set @column=''
set @columndata=''
fetch next from syscolumns_cursor into @name,@xtype
while @@fetch_status <>-1
begin
if @@fetch_status<>-2
begin
if @xtype not in(189,34,98) -- timestamp不需處理,image,text,ntext,sql_variant 暫時不處理
begin
set @column=@column+case when len (@column)=0 then'' else ','end+@name
set @columndata=@columndata+case when len (@columndata)=0 then '' else ','','','end
+case when @xtype in(167,175) then '''''''''+'+@name+'+''''''''' --varchar,char
when @xtype in(231,239) then '''n''''''+'+@name+'+''''''''' --nvarchar,nchar
when @xtype=61 then '''''''''+convert (char(23),'+@name+',121)+''''''''' --datetime
when @xtype=58 then '''''''''+convert (char(16),'+@name+',120)+''''''''' -- smalldatetime
when @xtype=36 then '''''''''+convert (char(36),'+@name+')+''''''''' -- uniqueidentifier
when @xtype in(35,99) then '''n''''''+'+'cast(replace(+cast('+@name+' as varchar(max)),'''''''','''''''''''') as varchar(max))'+'+''''''''' --nvarchar,nchar
else @name end
end
end
fetch next from syscolumns_cursor into @name,@xtype
end
--select *from syscolumns where id=object_id('','')
close syscolumns_cursor
deallocate syscolumns_cursor
set @sql='set nocount on select ''insert '+@tablename+'('+@column+') values (''as ''--'','+ @columndata+','')'' from '+@tablename
print '--'+cast(@sql as varchar(max))
exec(@sql)
if @ident is not null
print 'set identity_insert '+@tablename+' off'
記錄一種把樹結構的物件全部取到乙個集合中的寫法
乙個樹結構的物件,層次不限.可使用者自定義增加 如 public class org在查詢的時候直接封裝成乙個樹結構.listlist this.sqlfind sb.tostring org.class,params.toarray 查詢出所有部門id listresult new arrayli...
用乙個表的記錄更新另外乙個表
用table 1的address,phone number更新table 2的address,phone number,注意 1.set 後面加上要更新的列,有多個要更新的列時,加上多個列,2.where 後面加上table 1和table 2的關聯列,有多個關聯列時,加上多個列 3.rownum用...
用遞迴的方式得到乙個站點的全部鏈結
我的小蛛蛛還在慢慢的爬行著 今天遇到的問題是什麼呢?今天的問題是 想把這個站點的全部鏈結讀出的string 寫到檔案中去 用什麼方式呢?當然是遞迴!這個貌似別無選擇。對 的解釋 所以我們有了乙個引數 listnotbuidingfilekey 這個引數就是為了解決這個問題的。判斷這個檔案是不是存在的...