Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Figuring out Stored procedure

Author  Topic 

Bjcascone
Starting Member

37 Posts

Posted - 2009-11-23 : 19:17:04
I am working on a stored procedure that someone else wrote and i am trying to determine what this function is doing. Please let me know if you have any ideas. thanks

UPDATE a
SET Fielda= ISNULL(( SELECT SUM(1)
FROM Database..Tableb
WHERE a.DocNum = b.DocNum
AND a.ItemNum = b.ItemNum
AND ( (a.Validdate BETWEEN b.Validdate AND b.To
AND a.Id <> b.Id)
OR (a.To BETWEEN b.From AND b.To
AND a.Id <> b.Id))
),0)
FROM Database..Tableb a

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-11-25 : 01:30:53
If the result of the select statement is null it sets 0 else the same result to the column Fielda

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

kbhere
Yak Posting Veteran

58 Posts

Posted - 2009-11-25 : 01:58:52

ISNULL() is a function which is used for checking and handling null values..
The general syntax is,ISNULL check_expression , replacement_value )

Here, the check_expression in your UPDATE query is the (SELECT Query)

If this SELECT query returns null or it has no values to return, then this ISNULL() will replaces it with 0.. In your query, it is mentioned that the replacement_value is 0..
You can modify the replacement value as per your need..
I think this detailed description will help you understand much better..

Balaji.K
Go to Top of Page

kbhere
Yak Posting Veteran

58 Posts

Posted - 2009-11-25 : 01:59:47
The general syntax is,
ISNULL (check_expression , replacement_value)

Balaji.K
Go to Top of Page
   

- Advertisement -