欲执行一段SQL查询语句,要通过什么组件. ( 积分: 30 )

  • 主题发起人 主题发起人 5411
  • 开始时间 开始时间
5

5411

Unregistered / Unconfirmed
GUEST, unregistred user!
--加一含税价格为billstock

if not exists (select * from dbo.syscolumns where id = object_id(N'[dbo].[billStock]') and [name] = 'IncludeTaxPrice')
begin
ALTER TABLE BillStock ADD IncludeTaxPrice decimal(21,7) NULL
end


--添加一个期间的视图

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AD]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[AD]
GO
CREATE VIEW [dbo].[AD] AS
SELECT TOP 100 PERCENT AD2.ID AS BeginPeriod, AD1.ID AS EndPeriod,
AD2.StartDate AS StartDate, AD1.EndDate AS EndDate
FROM dbo.AccountDate AD1 INNER JOIN
dbo.AccountDate AD2 ON AD2.ID <= AD1.ID
ORDER BY AD2.ID
GO

--在表systemini中加几个键值--2005-10-5
if not exists(select * from systemini where sName = 'StartPeriod')
insert into dbo.systemini(sName,sValue,sMemo)
values('StartPeriod',null,null)

if not exists(select * from systemini where sName = 'ProfitTargetID')
insert into dbo.systemini(sName,sValue,sMemo)
values('ProfitTargetID',null,null)

if not exists(select * from systemini where sName = 'ProfitType')
insert into dbo.systemini(sName,sValue,sMemo)
values('ProfitType',null,null)

--加一自定义的函数
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[subjectIDtoLongName]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[subjectIDtoLongName]
GO
CREATE FUNCTION [subjectIDtoLongName] (@ID int)
RETURNS varchar(255) AS
BEGIN
declare @longName varchar(255)
select @longName = name from subject where id=@ID
while Exists(select * from subject where id = @ID)
begin
select @ID=TreeParent from subject where id = @ID
select @longName = isnull(Name,0) + '/' + @longName from subject where ID = @ID
end
return @longName
END
GO
=====================================================================
以上这些放在一个pack.sql文件中,要求是要从该文件中装载语句,然后执行.用什么组件?
 
--加一含税价格为billstock

if not exists (select * from dbo.syscolumns where id = object_id(N'[dbo].[billStock]') and [name] = 'IncludeTaxPrice')
begin
ALTER TABLE BillStock ADD IncludeTaxPrice decimal(21,7) NULL
end


--添加一个期间的视图

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[AD]') and OBJECTPROPERTY(id, N'IsView') = 1)
drop view [dbo].[AD]
GO
CREATE VIEW [dbo].[AD] AS
SELECT TOP 100 PERCENT AD2.ID AS BeginPeriod, AD1.ID AS EndPeriod,
AD2.StartDate AS StartDate, AD1.EndDate AS EndDate
FROM dbo.AccountDate AD1 INNER JOIN
dbo.AccountDate AD2 ON AD2.ID <= AD1.ID
ORDER BY AD2.ID
GO

--在表systemini中加几个键值--2005-10-5
if not exists(select * from systemini where sName = 'StartPeriod')
insert into dbo.systemini(sName,sValue,sMemo)
values('StartPeriod',null,null)

if not exists(select * from systemini where sName = 'ProfitTargetID')
insert into dbo.systemini(sName,sValue,sMemo)
values('ProfitTargetID',null,null)

if not exists(select * from systemini where sName = 'ProfitType')
insert into dbo.systemini(sName,sValue,sMemo)
values('ProfitType',null,null)

--加一自定义的函数
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[subjectIDtoLongName]') and xtype in (N'FN', N'IF', N'TF'))
drop function [dbo].[subjectIDtoLongName]
GO
CREATE FUNCTION [subjectIDtoLongName] (@ID int)
RETURNS varchar(255) AS
BEGIN
declare @longName varchar(255)
select @longName = name from subject where id=@ID
while Exists(select * from subject where id = @ID)
begin
select @ID=TreeParent from subject where id = @ID
select @longName = isnull(Name,0) + '/' + @longName from subject where ID = @ID
end
return @longName
END
GO
=====================================================================
以上这些放在一个pack.sql文件中,要求是要从该文件中装载语句,然后执行.用什么组件?
 
TQuery.CLose;
TQuery.SQL.LoadFromFile('Pack.SQL');
TQuery.Open;
 
TQUERY不能识别GO啊.楼上兄弟.
 
换成TADOQuery试试
 
一样,一样.不行.
 
用存储过程试试
 
不知提示的是什么错误
 
提示的意思是说,不能用GO
 
放到存储过程里就没问题,然后用TADOStoredProc调用,不过和你的要求不符
要不就只能进行SQL的解析,把每个go段进行分拆执行,没有问题,只是代码要麻烦一点,但很灵活
 
我看只好这么办了.
 
后退
顶部