to: pbsql(风云) 表变量? 程序中的代码(VB),假设: dim strSql as string strSql="insert into xxxxxxxxxxx insert into xxxxxxx insert into xxxxxxxx ........................ ........................ (10万个字符) "我还是不大清楚,能否具体一些?
既然是在程序中组合的,用ntext变量就行了嘛.
pbsql(风云)的解决方法确实值得考虑,text是不可以作为参数来使用的
--示例--写个执行组合语句的存储过程 create proc p_execute_sql @sql ntext --用ntext是防止处理中文时出现乱码 as exec(@sql) go--程序中调用的时候,只需要把组合的sql语句赋值给@sql这个参数就行了. --比如,VB中可以这样调用: Sub test() Dim iCmd As ADODB.Command
Set iCmd = New ADODB.Command With iCmd .ActiveConnection = iConc 'iConc是数据库连接字符串 .CommandType = 4 '类型为存储过程adCmdStoredProc
说点题外的,你那样处理效率极其低下,建议改成批处理: dim strSql as string strSql="insert into t(...) select ... union all select ... union all select ..."
declare @sql1 varchar(8000),@sql2 varchar(8000),@sql3 varchar(8000),.... set @sql1='select .............' set @sql2='select .............' set @sql3='select .............' .........exec(@sql1+@sql2+@sql3+...)
对于题外话的题外话, to pbsql(风云) select ... union all select ... 的用法需要合并多个输入表,挺废资源的, 以前试过,大概拼到1300-1500条的时候,就因为资源不够中断了, 所以这种方法并不适用于大批量数据insert
to pbsql(风云) 由于特殊原因。。———————————————————————————— to zjcxc(邹建) 原来exec可以直接用text/ntext的,问题基本上就解决了 SQL Server的text有时真搞不懂啊。谢谢参与的朋友 待回我试试,揭帖先。
表变量?
程序中的代码(VB),假设:
dim strSql as string
strSql="insert into xxxxxxxxxxx insert into xxxxxxx insert into xxxxxxxx
........................
........................ (10万个字符)
"我还是不大清楚,能否具体一些?
create proc p_execute_sql
@sql ntext --用ntext是防止处理中文时出现乱码
as
exec(@sql)
go--程序中调用的时候,只需要把组合的sql语句赋值给@sql这个参数就行了.
--比如,VB中可以这样调用:
Sub test()
Dim iCmd As ADODB.Command
Set iCmd = New ADODB.Command
With iCmd
.ActiveConnection = iConc 'iConc是数据库连接字符串
.CommandType = 4 '类型为存储过程adCmdStoredProc
.CommandText = "p_execute_sql" '调用的存储过程名
.Parameters.Refresh
.Parameters("@sql") = "程序中已经组合好的,要执行的sql语句"
'执行
.Execute
End With
End Sub
dim strSql as string
strSql="insert into t(...)
select ... union all
select ... union all
select ..."
set @sql1='select .............'
set @sql2='select .............'
set @sql3='select .............'
.........exec(@sql1+@sql2+@sql3+...)
select ...
union all select ...
的用法需要合并多个输入表,挺废资源的,
以前试过,大概拼到1300-1500条的时候,就因为资源不够中断了,
所以这种方法并不适用于大批量数据insert
由于特殊原因。。————————————————————————————
to zjcxc(邹建)
原来exec可以直接用text/ntext的,问题基本上就解决了
SQL Server的text有时真搞不懂啊。谢谢参与的朋友
待回我试试,揭帖先。