把程序改成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.   

    如果字段与access的关键字一样, 可能出现类似的错误. 试试加上[]
      

  2.   

    在ACCESS里把这个字段改为允许为空。
      

  3.   

    create table tb(id int, ItemNO varchar(32))
    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 
      

  4.   

    access的语法有些和sql server是不一样的,要多看他的帮助
      

  5.   

    access 里面如果是多表查询,那就在表的简称前面加上 AS 如 from item a 改为 from item AS a 
      

  6.   

    同意一楼,表和字段加[]试试
    select * from [table] where [user]
      

  7.   

    程序设计的问题和蝗虫一样多1、不要使用系统关键字(数据库、开发工具)作为表名、字段名,甚至开发工具的变量名,否则会出现很多意想不到的错误,你的上面明显犯了一个错误,不要使用table、item
    2、access通过不同连接方式连接,对默认值的支持相当的糟糕,也就是通过Borland系列开发工具连接ACCESS,ACCESS的默认值要关闭,而且还有一个就是数字采用长整形或者双精度型,至于为什么,可以参照MSDN中ADO部分的帮助及VCL中的代码
    3、ACCESS对嵌套子查询的支持相当的糟糕,你的代码本身就有问题
      

  8.   

    其实不是难度大。而是Access里功能限制了。
    没有SQL Server的灵活!
      

  9.   

    SELECT a.*, b.ItemContent, b.IsUsed
    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环境下调试通过的语句
      

  10.   

    关于排序:
    看你列出的数据,猜你的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
      但是这种方法在查询数据多的时候效率肯定低速度慢
      

  11.   

    create table tb(id int, ItemNO varchar(32))
    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 
      

  12.   

    写个函数,最多可处理5级,,,
    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