sql 语句定义的变量怎么在delphi中执行
sql 语句定义的变量如何在delphi中执行
如 我在写存储过程的sql语句如下:
decleare &MyId
selecte top 4 @aId=@aId+','+cast(id as varchar) from Mytable
我用delphi实现,不想用存储过程, 现在问题是在delphi中怎样执行这条sql语句,一执行就报错。
执行后怎么取出来。
谢谢!
------解决方案--------------------
格式不对,还有错字,符合语法就行了,像下面这样应该没错,没测试
如 我在写存储过程的sql语句如下:
decleare &MyId
selecte top 4 @aId=@aId+','+cast(id as varchar) from Mytable
我用delphi实现,不想用存储过程, 现在问题是在delphi中怎样执行这条sql语句,一执行就报错。
执行后怎么取出来。
谢谢!
------解决方案--------------------
格式不对,还有错字,符合语法就行了,像下面这样应该没错,没测试
- Delphi(Pascal) code
var s:string; begin s:='declare @MyId varchar(800)' +' set @MyId=''''' +' select top 4 @MyId=@MyId+','+cast(id as varchar(20)) from Mytable' +' select @MyId'; with adoquery1 do begin close; sql.text:=s; open; showmessage(fields[0].asstring);//取值 end; end;