Mssql中的变量在delphi中如何调用

牛魔王的表弟 2000-04-16 02:50:00
Mssql中:
create table table_1
(column_1 int not null,
column_2 char(10) null)
go
insert table_1 values (89,null)
go
declare @var1 int
set @var1=9
update table_1
set column_1=@var_1
where column_1=89
go
我想在delphi中动态的给@var_1赋值,这样的sql语句应该怎么写。
...全文
157 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
MikeZyx 2000-04-17
  • 打赏
  • 举报
回复
请问你的Table_1是临时表吗?如果是临时表,可用带参数的存储过程,非常方便,但要注意,在使用存储过程时可将临时表创建在Tempdb库中。
蝈蝈俊 2000-04-16
  • 打赏
  • 举报
回复

create table table_1
(column_1 int not null,
column_2 char(10) null)
go
insert table_1 values (89,null)
go
declare @var1 int
set @var1=9
update table_1
set column_1=@var_1
where column_1=89
go
看做是一个字符串。在需要的地方写入参数。
如:ss := 'declare @var1 int set @var1= '+参数+' update table_1 set mn_1=@var_1 where column_1=89 '
然后设置sql为这个字符串。执行就可以了。
附: 如果为char则;
ss := 'declare @var1 char set @var1= '+''''+参数+''''+' update table_1 set mn_1=@var_1 where column_1=89 '
具体情况我没试过。您根据这个思想就可以了。

另外一种方法是用存储过程。利用存储过程的ParamByName(const Value: String): TParam;动态的写入参数。

5,388

社区成员

发帖
与我相关
我的任务
社区描述
Delphi 开发及应用
社区管理员
  • VCL组件开发及应用社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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