Please tell what are the foreign keys you are using is that ids or names. Because your given seem to have names as foreign keys if it is so then.
1-SELECT CUSTOMER_NAME, ACCOUNT_NUMBER FROM DEPOSITOR WHERE DEPOSITOR_NAME LIKE '%Hayes%'
2-your other query is very lengthy and tricky it will take time to get sorted out still trying that... which language is you using at the front end? cann't you perform these checks at front end?
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
Skill Endorsements: 1
Check this code it may help you here all the entities with @ are user defined variables
DECLARE @Cutomer_ID varchar(50),@Customer_first_name varchar(50), @Customer_last_name varchar(50);
DECLARE @avgBlncs1 varchar(50), @countAccount1 varchar(50);
DECLARE @avgBlncs bigint;
DECLARE @countAccount bigint;
set @avgBlncs=0
set @countAccount=0
DECLARE contact_cursor CURSOR FOR
--SELECT customer_id, account_ID, balance FROM account
SELECT customer_id, customer_first_name, customer_last_name FROM customer
OPEN contact_cursor;
-- Perform the first fetch and store the values in variables.
FETCH NEXT FROM contact_cursor
INTO @Cutomer_ID,@Customer_first_name, @Customer_last_name;
-- Check @@FETCH_STATUS to see if there are any more rows to fetch.
WHILE @@FETCH_STATUS = 0
BEGIN
set @countAccount=(select count(account_id) from Account where customer_id=@Cutomer_ID )
set @avgBlncs= (select avg(balance)as Balance from Accounts where Customer_id=@Customer_ID
and (select count(account_id) from Account where Customer_id=@Customer_ID )>=2)
set @avgBlncs1=@avgBlncs
set @countAccount1=@countItem
-- Concatenate and display the current values in the variables.
--PRINT 'Count: '+@Cutomer_ID +'------'+ @Account+ ' ' + @Balance
PRINT =@Customer_ID+ ' '+@Customer_first_name+' '+@Customer_last_name; +' Has '+@avgBlncs1+ ' in ' + @countAccount1+' Accounts'
-- This is executed as long as the previous fetch succeeds.
FETCH NEXT FROM contact_cursor
INTO @Cutomer_ID,@Customer_first_name, @Customer_last_name;
END
CLOSE contact_cursor;
DEALLOCATE contact_cursor;
abelLazm
Postaholic
2,113 posts since Feb 2011
Reputation Points: 219
Solved Threads: 124
Skill Endorsements: 1