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.
| Author |
Topic |
|
akpaga
Constraint Violating Yak Guru
331 Posts |
Posted - 2010-03-08 : 14:25:43
|
| hi frendsi 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/09123 james mcds 09/08/09then i shoud get mcds- common shop as the query resulti 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 @Customersselect 234,'john','mcds','09/09/2009' union allselect 123,'james','burger','09/09/2009' union allselect 123,'james','mcds','09/08/2009'select shops_visted from @Customers group by shops_vistedhaving COUNT(distinct Customer_ID) = (select COUNT(distinct Customer_ID) from @Customers) |
 |
|
|
haroon2k9
Constraint Violating Yak Guru
328 Posts |
Posted - 2010-03-08 : 23:57:47
|
quote: Originally posted by akpaga hi frendsi 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/09123 james mcds 09/08/09then i shoud get mcds- common shop as the query resulti 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? |
 |
|
|
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. |
 |
|
|
|
|
|
|
|