将命令保存sqltxt文件|SQL Server数据库如何将多行查询代码执行结果导出到txt文件中

|

⑴ SQL…如何将表查询的结果自动保存到*.txt文件中

如果数据保存的对象表已经存在,insertinto结果表(字段1,字段2)select字段1,字段2from检索表where……如果如果数据保存的对象表尚未建立,可以偷懒,直接select字段1,字段2into结果表from检索表where……系统会自动按字段1,字段2建立结果表,字段属性从检索表继承

⑵ VF中怎样把SQL语句存储到命令文件、把查到的内容存到文本文件中一定要详细,回答满意的话加倍财富!

你好!vfp可以直接运行sql里的大部份语句。比如:select*from表where条件要把查询到的结果保存到txt文件只要在select*from表where条件后,加一条命令:tod:aa.txttypeDELIMITED仅代表个人观点,不喜勿喷,谢谢。

⑶ 怎样将数据库的sql语句的查询结果存到txt文本里

stringsql="select*fromtable"StringWritersw=newStringWriter("d:\Mysql.txt")sw.writeLine(sql)sw.flush()sw.Close()就这思路,自己完善

⑷ SQL Server数据库如何将多行查询代码执行结果导出到txt文件中

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[p_exporttb]') and OBJECTPROPERTY(id, N'IsProcere') = 1) drop procere [dbo].[p_exporttb] GO /*–数据导出Text导出查询语句中的数据到Text,包含字段名如果文件不存在,将自动创建文件基于通用性考虑,仅支持导出标准数据类型–邹建 2003.10–*/ /*–调用示例–导出Textp_exporttb @sqlstr='select * from 地区资料',@path='c:\',@over=1 –*/ create proc p_exporttb @sqlstr varchar(8000),–要导出的查询语句@path nvarchar(1000),–文件存放目录@fname nvarchar(250)='temp.txt',–文件名,默认为temp @over bit=0–是否覆盖已经存在的文件,如果不覆盖,则直接追加as declare @err int,@src nvarchar(255),@desc nvarchar(255),@out int declare @obj int,@constr nvarchar(1000),@sql varchar(8000),@fdlist varchar(8000)–参数检测if isnull(@fname,'')='' set @fname='temp.txt'–检查文件是否已经存在if right(@path,1)<>'\' set @[email protected]+'\' create table #tb(a bit,b bit,c bit) set @[email protected][email protected] insert into #tb exec master..xp_fileexist @sql if exists(select 1 from #tb where a=1)if @over=1beginset @sql='del '[email protected]exec master..xp_cmdshell @sql,no_outputendelseset @over=0 elseset @over=1–数据库创建语句set @[email protected][email protected] set @constr='Provider=Microsoft.Jet.OLEDB.4.0;Extended Properties="Text'+';HDR=YES;DATABASE='[email protected]+'"'–创建表的SQL declare @tbname sysname set @tbname='##tmp_'+convert(varchar(38),newid()) set @sql='select * into ['[email protected]+'] from('[email protected]+') a' exec(@sql)1.–连接数据库exec @err=sp_oacreate 'adodb.connection',@obj out if @err<>0 goto lberr exec @err=sp_oamethod @obj,'open',null,@constr if @err<>0 goto lberr2.–创建表的SQL select @sql='',@fdlist='' select @[email protected]+','+a.name,@[email protected]+',['+a.name+'] '+case when b.name in('char','nchar','varchar','nvarchar') then 'text('+cast(case when a.length>250 then 250 else a.length end as varchar)+')'when b.name in('tynyint','int','bigint','tinyint') then 'int'when b.name in('smalldatetime','datetime') then 'datetime'when b.name in('money','smallmoney') then 'money'else b.name end FROM tempdb..syscolumns a left join tempdb..systypes b on a.xtype=b.xusertype where b.name not in('image','text','uniqueidentifier','sql_variant','ntext','varbinary','binary','timestamp')and a.id=(select id from tempdb..sysobjects where [email protected]) select @sql='create table ['[email protected]+']('+substring(@sql,2,8000)+')',@fdlist=substring(@fdlist,2,8000) if @over=1 beginexec @err=sp_oamethod @obj,'execute',@out out,@sqlif @err<>0 goto lberr end exec @err=sp_oadestroy @obj set @sql='openrowset(''MICROSOFT.JET.OLEDB.4.0'',''Text;HDR=YES;DATABASE='[email protected]+''',''select * from ['[email protected]+']'')'–导入数据exec('insert into '[email protected]+'('[email protected]+') select '[email protected]+' from ['[email protected]+']') set @sql='drop table ['[email protected]+']' exec(@sql) return lberr:exec sp_oageterrorinfo 0,@src out,@desc out lbexit:select cast(@err as varbinary(4)) as 错误号,@src as 错误源,@desc as 错误描述select @sql,@constr,@fdlist go

⑸ 怎样把sql server数据库中的所有存储过程的代码,用SQL命令保存到和存储过程名相同的文本文件去

看看客户端连接工具有没有导出功能。

⑹ 如何把SQL命令存入文本文件

首先复制sql文到记事本,然后菜单“文件”,选择“另存为”,把文件名改为 XXX.sql 在把下面的文件类型改为“所有文件”。确定ok。这样就可以把你的sql保存成了文本文件,以后要运行就可以直接打开了。

⑺ 在SQL视图中完成以下查询,并将查询的SQL命令保存到以自己学号和姓名命名的.txt文件,

2.select *from 成绩记录视图 WHERE 课程号 NOT IN('0040930','0020257','0140624') and 成绩 BETWEEN 61 AND 65 3.select * from 学生记录视图 where datediff(year,出生日期,getdate())>27 5.select 学院,count(学号)from 学生记录视图 group by 学院 having count(学号)>2006.select sum(成绩) FROM 成绩记录视图 where 学号='2005214060' 7.select AVG(成绩) FROM 成绩记录视图 where 课程号='0120729'8.select MAX(成绩),MIN(成绩),MAX(成绩)-MIN(成绩) FROM 成绩记录视图 where 课程号='0120729' 9.select top count(*)/100 *FROM 学生记录视图ORDER BY 入学成绩 DESC 10.select *from 学生记录视图where (month(getdate())=month(出生日期)) and (day(出生日期) between day(getdate()) and day(getdate())+7) 第十题太模糊,没有表结构只能做这么多。手机弄真慢,我是提交一题,赶紧修改再添加一题。希望前面的你都看到了。 如果有哪些句子不理解,我可以逐条解释。

⑻ 如何将SQL语句存入文本文件

CMD中生成txt文档用 > *.txt你自己取名字就OK了 SQL语句命令后面直接跟上这个 > mysql.txt 就可以了…


赞 (0)