大力,还有几个问题

cgq214 2003-01-04 09:30:06
问题


1: EXEC master..xp_cmdshell 'bcp wt.dbo.m_table in E:\万泰 \db\temp.txt -c -q -S"cgq" -U"sa" -P""'

表可以是临时表吗,如果可以的话,怎么实现

...全文
97 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
cgq214 2003-01-04
  • 打赏
  • 举报
回复
我佩服你!!!
你是我在技术上第2个佩服的人!!

结贴
pengdali 2003-01-04
  • 打赏
  • 举报
回复
select
sum(case 尺码 when 1 then 1 end) xl,
sum(case 尺码 when 3 then 3 end) m1,
sum(case 尺码 when 5 then 5 end) sl
from 表 group by 物品
cgq214 2003-01-04
  • 打赏
  • 举报
回复
这个问题好了,太感谢了,你很厉害

问题:

数据在数据库表中如下
-------------------
物品 尺码
--------------------
01 1
01 3
01 5

怎么样变为
表单中如下
---------------------
物品 xl ml sl
-----------------------
01 1 3 5
pengdali 2003-01-04
  • 打赏
  • 举报
回复
select * into ##tmp from ckb
EXEC master..xp_cmdshell 'bcp ##tmp in E:\万泰\db\ckb.txt -c -q -S"cgq" -U"sa" -P"sa"'
select * from ##tmp
drop table ##tmp
或:
select * into ##tmp from ckb
EXEC master..xp_cmdshell 'bcp tempdb.dbo.##tmp in E:\万泰\db\ckb.txt -c -q -S"cgq" -U"sa" -P"sa"'
select * from ##tmp
drop table ##tmp
cgq214 2003-01-04
  • 打赏
  • 举报
回复
Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]忽略了数据库名称 'tempdb',将引用 tempdb 中的对象。
pengdali 2003-01-04
  • 打赏
  • 举报
回复
select * into ##tmp from ckb
EXEC master..xp_cmdshell 'bcp tempdb.dbo.#tmp in E:\万泰\db\ckb.txt -c -q -S"cgq" -U"sa" -P"sa"'
select * from ##tmp
drop table ##tmp
cgq214 2003-01-04
  • 打赏
  • 举报
回复
Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]忽略了数据库名称 'wt',将引用 tempdb 中的对象。
cgq214 2003-01-04
  • 打赏
  • 举报
回复
Error = [Microsoft][ODBC SQL Server Driver][SQL Server]对象名 '#tmp' 无效。
cgq214 2003-01-04
  • 打赏
  • 举报
回复
Warning = [Microsoft][ODBC SQL Server Driver][SQL Server]忽略了数据库名称 'wt',将引用 tempdb 中的对象。
pengdali 2003-01-04
  • 打赏
  • 举报
回复
select * into ##tmp from ckb
EXEC master..xp_cmdshell 'bcp wt.dbo.#tmp in E:\万泰\db\ckb.txt -c -q -S"cgq" -U"sa" -P"sa"'
select * from ##tmp
drop table ##tmp
pengdali 2003-01-04
  • 打赏
  • 举报
回复
全局临时表试试:
select * into ##temp1 from ckb
cgq214 2003-01-04
  • 打赏
  • 举报
回复
select * into #tmp from ckb
EXEC master..xp_cmdshell 'bcp wt.dbo.#tmp in E:\万泰\db\ckb.txt -c -q -S"cgq" -U"sa" -P"sa"'
select * from #tmp
drop table #tmp
pengdali 2003-01-04
  • 打赏
  • 举报
回复
你是想导入还是导出???
cgq214 2003-01-04
  • 打赏
  • 举报
回复
我用
select * into #tmp form ckb
建立临时表,可是执行的时候不行
pengdali 2003-01-04
  • 打赏
  • 举报
回复
"a ", "b ", "c ", "d ", "e "
00001, 7398,MICROSOFT PRESS SPECIAL,49.99, 0-7356-0652-8
00002, 7832, MICROSOFT - WWF , 45.63, 0-4562-0582-5
00003, 5643, MICROSOFT - WWF , 21.5 , 0-5545-0457-7

临时表:

用SELECT * into #临时表 FROM OPENROWSET('MSDASQL.1','Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=e:\','select * from a.txt')

导入到sql

用INSERT INTO table1(a,b,c,d) SELECT * FROM OPENROWSET('MSDASQL.1','Driver={Microsoft Text Driver (*.txt; *.csv)};Dbq=e:\','select * from a.txt')
pengdali 2003-01-04
  • 打赏
  • 举报
回复
可以用真实表代替仿真临时表
EXEC master..xp_cmdshell 'bcp 库名.dbo.临时表 in E:\万泰\db\temp.txt -c -q -S"cgq" -U"sa" -P""'

insert 真正表 select * from 仿真临时表
drop table 仿真临时表

22,210

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server 疑难问题
社区管理员
  • 疑难问题社区
  • 尘觉
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧