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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 common value

Author  Topic 

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2010-03-08 : 14:25:43
hi frends

i have a table customer with follwoing info,

customer_id,customer_name , shops_visted,vist_date.
i.e
234 john mcds 09/09/09
123 james burger king 09/09/09
123 james mcds 09/08/09

then i shoud get mcds- common shop as the query result

i have another table cust_addr with customer_id,customer _address.

i want to check if any of the customer has visted the same shop during a specifi time and then use that id to get the address in the second table but my main criteria is to get the common shop from the customer table...

how can i achieve this thank you in advance

ddramireddy
Yak Posting Veteran

81 Posts

Posted - 2010-03-08 : 23:51:00
declare @Customers table
(
customer_id int,
customer_name varchar(100),
shops_visted varchar(100),
vist_date datetime
)
insert into @Customers
select 234,'john','mcds','09/09/2009' union all
select 123,'james','burger','09/09/2009' union all
select 123,'james','mcds','09/08/2009'

select shops_visted from @Customers
group by shops_visted
having COUNT(distinct Customer_ID) = (select COUNT(distinct Customer_ID) from @Customers)
Go to Top of Page

haroon2k9
Constraint Violating Yak Guru

328 Posts

Posted - 2010-03-08 : 23:57:47
quote:
Originally posted by akpaga

hi frends

i have a table customer with follwoing info,

customer_id,customer_name , shops_visted,vist_date.
i.e
234 john mcds 09/09/09
123 james burger king 09/09/09
123 james mcds 09/08/09

then i shoud get mcds- common shop as the query result

i have another table cust_addr with customer_id,customer _address.

i want to check if any of the customer has visted the same shop during a specifi time and then use that id to get the address in the second table but my main criteria is to get the common shop from the customer table...

how can i achieve this thank you in advance



Could you please show some sample data with Expected Output?
Go to Top of Page

akpaga
Constraint Violating Yak Guru

331 Posts

Posted - 2010-03-09 : 10:01:02
thansk for your response harron. i put my main requirement sample output in my question itself.
Go to Top of Page
   

- Advertisement -