C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Forums » .NET » SQL Server »

SQL SERVER


Posted Date: 30 Aug 2008      Posted By: pallavi satish punekar      Member Level: Gold     Points: 1   Responses: 1



i have a problem in SQL SERVER 2005 isnull function


i have query lk this


select isnull(sum(a.Totalreceipt),0)
from GRNrmdayconsolidated a
where convert(varchar(10),a.ReceiptDate,120)='2008-008-28'
group by a.itemcode,a.vendorid


If there r no records with this date it wil retum nothing
bt same query if i remove the group by clause
select isnull(sum(a.Totalreceipt),0)
from GRNrmdayconsolidated a
where convert(varchar(10),a.ReceiptDate,120)='2008-008-28'


when there is no record it wil return 0

again in the same query if i remove the sum
select isnull((a.Totalreceipt),0)
from GRNrmdayconsolidated a
where convert(varchar(10),a.ReceiptDate,120)='2008-008-28'


It wil nt return any thing


What is the problem in frist and last query and how isnull function works





Responses

Author: Venkatesan Prabu .J    31 Aug 2008Member Level: DiamondRating: 2 out of 52 out of 5     Points: 6

I am not clear about your needs. Any way, let me explain some key concepts in your query,
Below query will fetch the sum of your receipt on the specific date.
If the sum value is null , then 0 will be replaced, in the below query you will get multiple rows grouped under itemcode and vendor id

select isnull(sum(a.Totalreceipt),0)
from GRNrmdayconsolidated a
where convert(varchar(10),a.ReceiptDate,120)='2008-008-28'
group by a.itemcode,a.vendorid


In this code you will get a single row with sum of the values on the specific date.


select isnull(sum(a.Totalreceipt),0)
from GRNrmdayconsolidated a
where convert(varchar(10),a.ReceiptDate,120)='2008-008-28'


Here you will get the exact data on the specific date.


select isnull((a.Totalreceipt),0)
from GRNrmdayconsolidated a
where convert(varchar(10),a.ReceiptDate,120)='2008-008-28'


Regards,
Venkatesan prabu .J
http://venkattechnicalblog.blogspot.com/



Post Reply

 This thread is locked for new responses. Please post your comments and questions as a separate thread.
If required, refer to the URL of this page in your new post.


Next : How to make schedular in Ms-Sql
Previous : New to sql
Return to Discussion Forum
Post New Message
Category: SQL Server

Related Messages



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use