把程序改成access的之后,竟然出现了N多问题,非常着急,麻烦大家帮忙看一下。2007年最后一个工作日了,祝大家新年快乐先~~~
1、查询里面可以执行,程序里面却不可以,报错:至少一个参数没有被指定(在paramcheck设置为是时报“参数b.Isused没有默认值”):
select a.*,b.ItemContent,b.IsUsed from item a left join (select * from Bargaincontent where Bargainid=1) b on a.itemNO = b.itemNo where a.templateid =1 order by a.ItemNO
程序:with ADOQueryLoadTree do
begin
Close;
SQL.Clear;
上面语句
SQL.Add(szSQL);
Open;
end;
2、排序:
id ItemNO
1 1.4.6.4
1 1.4.6.5
1 10
1 11
1 2
1 2.1
1 2.1.1
想实现10、11排到2,2.1等的后面3、事务+多条sql语句
insert into table1;
insert into table1;
在网上查的,后面加;加#13等都试过了,还是不行,到底是个什么样的格式?
1、查询里面可以执行,程序里面却不可以,报错:至少一个参数没有被指定(在paramcheck设置为是时报“参数b.Isused没有默认值”):
select a.*,b.ItemContent,b.IsUsed from item a left join (select * from Bargaincontent where Bargainid=1) b on a.itemNO = b.itemNo where a.templateid =1 order by a.ItemNO
程序:with ADOQueryLoadTree do
begin
Close;
SQL.Clear;
上面语句
SQL.Add(szSQL);
Open;
end;
2、排序:
id ItemNO
1 1.4.6.4
1 1.4.6.5
1 10
1 11
1 2
1 2.1
1 2.1.1
想实现10、11排到2,2.1等的后面3、事务+多条sql语句
insert into table1;
insert into table1;
在网上查的,后面加;加#13等都试过了,还是不行,到底是个什么样的格式?
解决方案 »
- 关于delphi7写的通信软件运行时,速度时快时慢问题
- 高分求直接调用ZLib单元实现压缩解压缩byte数组的函数,累了一晚上都搞不定,郁闷了
- 谁写过用delphi 访问Lotus notes
- 如何通过字符串调用类的方法
- 急啊 如何判断 某个数据库在指定位置是否存在啊???怎样动态建立数据库??如何判断某个表是否存在 如何建立
- fastreport怎么实现这样的报表??
- 关于D7的Rave5中的TRvNDRWrite,TRvRenderPreview,那位有使用经验啊
- 如何获取本地路径的上一目录
- fastreport中宽行纸如何设置
- 怎樣在報表中的數字中間加逗號分隔符﹐如1382356.58 變為1,382,356.58
- invalid index??
- 一个关于 ppchar 的语法问题!求达人解惑!!!
insert tb select 1, '1.4.6.4'
union all select 1, '1.4.6.5'
union all select 1, '10'
union all select 1, '11'
union all select 1, '2'
union all select 1, '2.1'
union all select 1, '2.1.1'select * from tb
order by cast(substring(ItemNO, 1, charindex('.', ItemNO+'.')-1) as int), ItemNO/*
id ItemNO
----------- --------------------------------
1 1.4.6.4
1 1.4.6.5
1 2
1 2.1
1 2.1.1
1 10
1 11(7 row(s) affected)
*/drop table tb
select * from [table] where [user]
2、access通过不同连接方式连接,对默认值的支持相当的糟糕,也就是通过Borland系列开发工具连接ACCESS,ACCESS的默认值要关闭,而且还有一个就是数字采用长整形或者双精度型,至于为什么,可以参照MSDN中ADO部分的帮助及VCL中的代码
3、ACCESS对嵌套子查询的支持相当的糟糕,你的代码本身就有问题
没有SQL Server的灵活!
FROM item AS a LEFT JOIN [select * from Bargaincontent where Bargainid=1]. AS b ON a.itemNO=b.itemNo
WHERE a.templateid=1
ORDER BY a.ItemNO;--以上语句是我在ACCESS2000环境下调试通过的语句
看你列出的数据,猜你的ItemNo列是一个字符列,而字符排序是按ASCII码排序的,
所以在比较"10"与"2.1"值的时候会是"1"与"2"比较,"0"与"."比较,
因此会形成上你的排序结果,如果想要实现你的要求,那么你可以:
1.将全部字符宽度对齐,比如你的ItemNo里最多的可能会有"1000.1000.101",那么你的全部数据可能需要修改成形如"0001.0004.006.4"这样的形式,这样排序后会是你要求的结果
2.如果不能修改ItemNo的存储格式 ,那么将ItemNo的字符属性的值使用一个函数f()将其转换成数字型值再排序,
这个函数可能比较麻烦,举例来说若ItemNo值为"1.4.6.4",你可以使用如下计算方法:1*10^3+4*10^2+6*10^1+4*10^0
但是这种方法在查询数据多的时候效率肯定低速度慢
insert tb select 1, '1.4.6.4'
union all select 1, '1.4.6.5'
insert tb select 1, '1.4.6.10' --这里 这样排序的话 '1.4.6.10'会在'1.4.6.4'的前面
union all select 1, '1.4.6.11' --这里
union all select 1, '10'
union all select 1, '11'
union all select 1, '2'
union all select 1, '2.1'
union all select 1, '2.1.1'select * from tb
order by cast(substring(ItemNO, 1, charindex('.', ItemNO+'.')-1) as int), ItemNO/*
id ItemNO
----------- --------------------------------
1 1.4.6.4
1 1.4.6.5
1 2
1 2.1
1 2.1.1
1 10
1 11(7 row(s) affected)
*/drop table tb
create table tb(id int, ItemNO varchar(16))
insert tb select 1, '1.4.6.4'
union all select 1, '1.4.6.5'
union all select 1, '1.4.6.2'
union all select 1, '1.4.6.13'
union all select 1, '1.4.6.3.9'
union all select 1, '1.4.6.3.10'
union all select 1, '1.4.6.3.11'
union all select 1, '10'
union all select 1, '11'
union all select 1, '2'
union all select 1, '2.1'
union all select 1, '2.1.1'go
create function fn_Hash(@ItemNO varchar(16))
returns bigint as
begin
declare @result bigint, @multiple int
select @result=0, @multiple=4
while charindex('.', @ItemNO)>0
begin
select @result=@result+left(@ItemNO, charindex('.', @ItemNO)-1)*power(100,@multiple)
, @ItemNO = right(@ItemNO, len(@ItemNO)-charindex('.', @ItemNO))
,@multiple=@multiple-1
end
select @result=@result+@ItemNO*power(100,@multiple)
return @result
end
goselect * from tb
order by dbo.fn_Hash(ItemNO)/*
id ItemNO
----------- ----------------
1 1.4.6.2
1 1.4.6.3.9
1 1.4.6.3.10
1 1.4.6.3.11
1 1.4.6.4
1 1.4.6.5
1 1.4.6.13
1 2
1 2.1
1 2.1.1
1 10
1 11(12 row(s) affected)
*/drop function dbo.fn_Hash
drop table tb