delphi里这个sql语句如何执行?
sql语句如下:
with tb(id,姓名) as(
select 1,'刘德华' union all
select 2,'张学友' union all
select 3,'黎明' union all
select 4,'郭富城')
select * from tb
这句sql放到delphi里 老是说‘关键字with’附近有语法错误
with ADOQuery2 do
begin
Close;
SQL.Clear;
SQL.Text:='with tb(id,姓名) as( select 1,''刘德华'' union all select 2,''张学友'' union all select 3,''黎明'' union all select 4,''郭富城'') select * from tb';
ExecSQL;
end;
请大家帮我测试一下
[解决办法]
注意CTE语句,到SQL SERVER服务器是当作一个SQL脚本来执行的,With前需加上";",如下:
ADOQuery2.SQL.Text:=';with tb(id,姓名) as( select 1,''刘德华'' union all select 2,''张学友'' union all select 3,''黎明'' union all select 4,''郭富城'') select * from tb';
ADOQuery2.Open;