Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > Putting it Together > Databases

Reply
 
LinkBack Thread Tools
Old February 7th, 2006, 10:21 AM   #1
New Member
 

Join Date: Sep 2005
Posts: 24
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 ClaireB is on a distinguished road
Help! Too complex for me!

Hi guys,

I'm trying to modify an SQL statement to include some more information from yet another table but without adding any more records. Sorry but this is a long one.

Here is the SQL:
Select Status.ID,
Status.ClaimantID,
(Campaign.Claimant_Firstname +' '+ Campaign.Claimant_Lastname) As FullName,
Status.PolicyID
from PolicyStatus Status
INNER JOIN Campaign ON Campaign.UniqueKey = Status.ClaimantID
where Status.ID = ( select top 1 StatusSubSearch.ID
from PolicyStatus StatusSubSearch
INNER JOIN PolicyStatus_Actions Actions ON Actions.ID = StatusSubSearch.StageAction
where Status.ClaimantID = StatusSubSearch.ClaimantID
AND Status.PolicyID = StatusSubSearch.PolicyID
AND Actions.OverviewIgnoreAction <>1
order by StatusSubSearch.DateAdded desc)
Order By Status.StatusDate,Status.StatusTime


The tables include the following fields which are nvarchar unless otherwise stated, and relate to each other as follows:

Campaign Table - This table holds all primary policy information
UniqueKey - primary key , has a one to many relationship with the ClaimantIDs
Claimant_Firstname
Claimant_Lastname
IsDeleted - bit field

PolicyStatus
ID
ClaimantID - has a many to one relationship with the UniqueKey
PolicyID - each claimantID can have many policies
StatusDate
StatusTime

PolicyInformation - This table holds all additional policy information (policy 2, policy 3 etc)
ClaimantID - has a many to one relationship with the UniqueKey
PolicyID - each claimantID can have many policies
IsDeleted

SQL statement and tables currently produce something similar to this

ID ClaimantID Name PolicyID
59159 5034 Stewart Scott 4
45870 11182 SUSAN JONES 2
66303 18212 Mark Kirven 1
50521 5104 Mervyn Neal 1
2386 35786 Kevin Ryder 2

I want to amend the SQL statement so that it still produces the same current information, but also tells me if the policy has been deleted. For example the above data would be like:

ID ClaimantID Name PolicyID Deleted

59159 5034 Stewart Scott 4 1

45870 11182 SUSAN JONES 2 0
66303 18212 Mark Kirven 1 0
50521 5104 Mervyn Neal 1 1
2386 35786 Kevin Ryder 2 0

Where for IDs 66303 and 50521 the deleted info is obtained from the IsDeleted column in the Campaign Table, but the info for the other rows where the policy ID is 2 or 4 the IsDeleted column is referenced from the Policy Information Table.

I've tried various JOINs but don't seem to be able to retain the original number of records. Can anyone help? Thanks to all those who've read this far!
ClaireB is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old February 15th, 2006, 07:20 PM   #2
WebForumz Member
 

Join Date: Feb 2004
Location: Woodbridge, UK
Age: 29
Posts: 80
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 Trebz is on a distinguished road
Re: Help! Too complex for me!

To get the IsDeleted from the campaign table, you can just add (below line 4 in your example) "Campaign.IsDeleted as Deleted" to get that.

Is this in access? If it is, then I will be of limited help, as I would only know how to do it in SQL, and there is plenty of that which will work with MS SQL Server, but not with access.

You say for some rows, the 'Deleted' column needs to get it's data from different places, by what condition is this?
Trebz is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks

Tags
help , complex


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Complex Button RollOver/RollOut Effects Problems. Toby1979 Flash and ActionScript 6 July 13th, 2007 12:12 PM
iframe's: slightly complex, need help deymeraff HTML, XHTML and CSS 0 June 8th, 2007 12:02 AM
Complex flash site, can anyone help???? Ashdude2000 Flash and ActionScript 4 November 20th, 2006 10:01 AM
Complex update with check boxes jpresley Classic ASP 0 September 27th, 2006 04:57 PM
Designing complex site layouts gwx03 HTML, XHTML and CSS 6 November 29th, 2003 10:23 PM


Search Engine Optimization by vBSEO 3.2.0 RC8