Delphi:Delphi和Microsoft SQL Server 2005从函数值进行错误的计算 [英] Delphi: Delphi and Microsoft SQL Server 2005 bad calculations from function values

查看:55
本文介绍了Delphi:Delphi和Microsoft SQL Server 2005从函数值进行错误的计算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用Microsoft SQL Server Management Studio在SQL Server 2005上发送此查询时

  SELECT dbo.MOV('Hi ',10,2)+ dbo.MOV('Hi2',8,2)

查询返回400



任何发送到该函数的结果将返回200,除非最后两个
参数(其中0的返回值是100且该值函数的Decimal(12,2)返回类型:



问题出在我对Delphi进行查询时

  Query.SQL.Add('SELECT dbo.MOV(``Hi'',10,2)+ dbo.MOV(``Hi2'',8,2) '); 
Query.Open;
Query.Next;
ShowMessage(Query.Fields [0] .AsString);

查询返回200(在消息对话框上),就像SQL Server仅采用第一个函数一样并忽略第二个,因此我可以从SQL Server 2005中获得在Delphi中进行正确计算的功能。谢谢。

解决方案

尝试在Query.SQL.Add之前清除Query.SQL。

  Query.SQL.Clear 
Query.SQL.Add('SELECT dbo.MOV(``Hi'',10,2)+ dbo.MOV( ``Hi2'',8,2)');

如果您已经在SQL中存储了查询,则只会看到第一个查询的结果。 / p>

When i send this query on SQL Server 2005 with the Microsoft SQL Server Management Studio

SELECT dbo.MOV('Hi',10,2) + dbo.MOV('Hi2',8,2)

The query returns 400

The result of anything send to the function will return 200 except if the last two parameter where 0 the value of return will be 100 and the value type of return from the function its Decimal(12,2)

the problem, comes when I do the query on Delphi

Query.SQL.Add('SELECT dbo.MOV(''Hi'',10,2) + dbo.MOV(''Hi2'',8,2)');
Query.Open;
Query.Next;
ShowMessage(Query.Fields[0].AsString);

The Query returns 200 (on the message dialog), like if SQL Server is just taking the first Function and ignoring the second one, so what i could do get from SQL Server 2005 the right calculation in Delphi. Thanks.

解决方案

Try to clear Query.SQL before Query.SQL.Add.

Query.SQL.Clear
Query.SQL.Add('SELECT dbo.MOV(''Hi'',10,2) + dbo.MOV(''Hi2'',8,2)');

If you already have a query stored in SQL you will only see the result from the first one.

这篇关于Delphi:Delphi和Microsoft SQL Server 2005从函数值进行错误的计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆