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.
| Author |
Topic |
|
imranabdulaziz
Yak Posting Veteran
83 Posts |
Posted - 2010-05-17 : 06:40:24
|
| I have two table Master and TransactionIn master table I define set of essential good without it set is not complete. Master table likeproductgroup product Minimum qty Bookset Book A 1 Bookset Book B 1 And transactional table where request received is likesysid Product group Product Qty Request complete flag1 Bookset Book A 5 Complete1 Bookset Book B 2 Complete2 Bookset Book A 6 IncompleteI want to know In Transactional whether a request of is having minimum Qty. That is if request of product group BookSet comes then it should have each product of Book A and Book B That is why sysid 1 request is complete and 2 is Incomplete. |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-05-17 : 11:56:57
|
create a udf like belowCREATE FUNCTION IsComplete(@sysid int)RETURNS BitASBEGINDECLARE @Result bitSELECT @Result = CASE WHEN EXISTS(SELECT 1 FROM Master m LEFT JOIN (SELECT Product FROM Transaction WHERE sysid=@sysid)t ON t.Product = m.Product AND t.productgroup = m.productgroup WHERE t.Product IS NULL) THEN 0 ELSE 1 ENDRETURN @Result ENDthen create RequestCompleteFlag as a derived qty asRequestCompleteFlag AS CASE WHEN dbo.IsComplete(sysid)=1 THEN 'Complete' ELSE 'Incomplete' END ------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
|
|
|