sql函数总是返回null [英] sql function returning null always

查看:174
本文介绍了sql函数总是返回null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好朋友,

我正在使用sqlserver函数,该函数一直工作到昨天。但是每当我使用它时,返回null avlues。请帮我。这是批量生产,但仍然无法正常运行。

Hello friends ,
I am using a sqlserver function that was working file till yesterday. But returning null avlues today whenever i am using it. Please help me. This is wroking as batch but still not working as a function.

create FUNCTION [dbo].[planame](@custid int, @dBillDate datetime)            
RETURNS VARCHAR(MAX)            
BEGIN            
--RETURN LTRIM(RTRIM(@string))            
declare @planname VARCHAR(MAX)            
if exists (  select top 1  tp.planName from  tNetServicePlans tp             
inner join tnetserviceplanshistroy ch on ch.planId=tp.planId        
--inner join  tnetbill b on b.custid=ch.custid            
--where cast(ch.updatedate as date)<=cast(@dBillDate as date)   
where convert(datetime,ch.updatedate,105)<=convert(datetime,'4/1/2013',105)        
and ch.custid=1       
order by ch.updatedate   desc         
 )            
begin           
 select top 1  @planname=tp.planName from  tNetServicePlans tp             
inner join tnetserviceplanshistroy ch on ch.planId=tp.planId            
--inner join  tnetbill b on b.custid=ch.custid            
where convert(datetime,ch.updatedate,105)<=convert(datetime,'4/1/2013',105)        
and ch.custid=1        
order by ch.updatedate   desc          
            
end          
return @planname            
END      



请帮帮我朋友。


Please help me friends.

推荐答案

正如其他人已经提到的那样,这是不可能的告诉我,没有数据会有什么问题 - 尤其是在约会之前它正在做我的工作。

幸运的是,SQL Management Studio有很好的调试功能 [ ^ ]。

尝试调试你的函数!

你可以使用这些功能或以旧的方式使用它:通过函数的逻辑思考并对数据发出部分查询以查看什么是错的。

一个注意事项:你从不使用@custid参数,但每次添加custid = 1条件。这个id是否存在,它是否具有今天的任何值?
As the others already mentioned, it is quite impossible to tell, what''s wrong without data - especially when it was doing i''ts job until a date.
Fortunately, SQL Management Studio has good debugging features[^].
Try debugging your function!
You can use those features or take it in the old way: think trough the logic of the function and issue partial queries on your data to see what''s wrong.
One note: you never use @custid parameter, but every time you add a "custid=1" condition. Does that id exist, and does it has any values for today?


告诉所有朋友。这是架构的问题,

当我用这样的dbo.tnetserviceplanshistroy这样的架构编写tnetserviceplanshistroy。

它工作正常。谢谢大家帮助我
thnk u all friends . it was the problem of schema ,
when i wrote tnetserviceplanshistroy with schema like this dbo.tnetserviceplanshistroy .
it is working fine .thank you all for helping me


这篇关于sql函数总是返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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