SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 No Matching Record
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

divan
Posting Yak Master

153 Posts

Posted - 06/24/2013 :  12:10:10  Show Profile  Reply with Quote
Friends;

I have two tables

E0025_0604 which has the following rows

POLICY_NUMBER TAIL_PREM
TX 10063 8763.00
TX 10063 19469.00
TX 10063 22982.00
TX 10063 22982.00


AND PREMIUM_DETAIL

POLICY_NUMBER PREMIUM
TX 10063 8763.00
TX 10063 19469.00
TX 10063 22982.00
TX 10063 22984.00

of course there are a lot more records and a lot more fields in each table but i just select one policy..

I have written the following script

SELECT DISTINCT POLICY_NUMBER, TAIL_PREM
INTO #TEMP1
FROM E0025_0604
WHERE TAIL_PREM <> 0
AND POLICY_NUMBER = 'TX 10063'
AND POLICY_NUMBER NOT LIKE 'Q%'
SELECT * FROM #TEMP1 ORDER BY POLICY_NUMBER, TAIL_PREM


SELECT DISTINCT P.POLICY_NUMBER,P.PREMIUM_LOB,P.PREMIUM,P.BILLED_PREMIUM,P.WRITTEN_PREMIUM,P.ANNUALIZED_PREMIUM,P.FULL_TERM_PREM
FROM PREMIUM_DETAIL P
INNER JOIN #TEMP1 T ON P.POLICY_NUMBER = T.POLICY_NUMBER
WHERE P.PREMIUM_LOB LIKE 'T%'
ORDER BY P.POLICY_NUMBER,P.PREMIUM_LOB, P.PREMIUM

Can someone please help..

Thanks




What I am trying to get from this script to select/display all records that are not in either table for a particular policy..


visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/24/2013 :  12:28:33  Show Profile  Reply with Quote
Show us what will your expected output for the posted data

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 06/24/2013 :  13:13:09  Show Profile  Reply with Quote
I am expecting the following from premium_detail to show up

TX 10063 22984.00
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/24/2013 :  13:30:18  Show Profile  Reply with Quote
ok. so this?

SELECT POLICY_NUMBER, TAIL_PREM
FROM
(
SELECT POLICY_NUMBER, TAIL_PREM, 1 AS Cat
FROM E0025_0604
WHERE POLICY_NUMBER = 'TX 10063' 
UNION ALL
SELECT POLICY_NUMBER, PREMIUM,2
FROM PREMIUM_DETAIL
WHERE POLICY_NUMBER = 'TX 10063' 
)t
GROUP BY POLICY_NUMBER, TAIL_PREM
HAVING COUNT(DISTINCT Cat) = 1


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

divan
Posting Yak Master

153 Posts

Posted - 06/24/2013 :  14:12:06  Show Profile  Reply with Quote
Thanks... It works great
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

Posted - 06/25/2013 :  00:51:38  Show Profile  Reply with Quote
welcome

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.09 seconds. Powered By: Snitz Forums 2000