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
 Request for Query Hint

Author  Topic 

aswindba1
Yak Posting Veteran

62 Posts

Posted - 2013-12-23 : 00:12:21
Table 1 : custemaildim
emailADDr |||||| SendSurvey
some@gmail.com|||||| N
exam@gmail.com|||||| y
test@gmail.com|||||| Y

Table 2: Unsubscribe
emailADDr |||||| Sno
exam@gmail.com |||||| 2
new1@gmail.com |||||| 2



Requirement :
1. Initially passing the email address to custemaildim table to find out the Send Survey Flag.

So here we will get send survey flag would be Yes or No from the above table.

2. So we have the send survey flag either Yes or No
3. Let’s take Send Survey Flag has Yes.
a. Find the email address exists in unsubscribe table. If it doesn’t have the email address exists in unsubscribe table. Flag return yes flag.
b. If it does have a email address exists in unsubscribe table return No flag.
4. Let’s take Send Survey Flag has No.
a. Here it’s send survey flag is no. We don’t need to look up on the unsubscribe table just return No flag.

5. If the email address does not exist in the custemaildim table find that email address exist in the unsubscribe table if it has that email Address return NO flag. If it does not exist on both tables then it return YES flag.

waterduck
Aged Yak Warrior

982 Posts

Posted - 2013-12-23 : 04:44:55
hey....do take note that query hint and how to query is 2 different thing
http://technet.microsoft.com/en-us/library/ms181714.aspx
Go to Top of Page

waterduck
Aged Yak Warrior

982 Posts

Posted - 2013-12-23 : 04:51:43
[code]
declare @custemaildim table(emailADDr varchar(50), SendSurvey varchar)
insert into @custemaildim select
'some@gmail.com', 'N' union all select
'exam@gmail.com', 'y' union all select
'test@gmail.com', 'Y'

declare @Unsubscribe table(emailADDr varchar(50), Sno int)
insert into @Unsubscribe select
'exam@gmail.com', 2 union all select
'new1@gmail.com', 2

--This is to find the email address is in custemaildim
SELECT *
FROM @custemaildim
WHERE emailADDr = 'some@gmail.com'

--This is to find the email address is in Unsubscribe
IF EXISTS(SELECT * FROM @Unsubscribe WHERE emailADDr = 'some@gmail.com')
SELECT 'YES'
ELSE
SELECT 'NO'

--So now you need to think how to get this 2 thing work together
[/code]
Go to Top of Page
   

- Advertisement -