Click here to Skip to main content
15,886,796 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi here is my database design which consist of following 3 tables vedor,products and brands. their def are as follows
SQL
vendor(
vid int primary key identity,
v_name varchar(50),            -- name of vendor
v_producttype varchar(50)      -- type of product eg appreals or non-appreals etc
);

products(
p_id int primary key identity,
vref_id int foreign key references vendor(vid), -- refers to vid of vendor
produts varchar(50)                             -- refers to products
)

brands(
b_id int primary key identity
vref_id int foreign key references vendor(vid), -- refers to vid of vendor
brands varchar(50)                              -- refers to various brands
) 

now as one can see one vendors can have many products as well as many brands
what i want to do is to display all products as well as brands belonging to particular vendor in a single cell of a (dumy) table where vendro details are displayed

how to this. i have tried using sql equi-joins but every time rows get repeated for every products. what should i do use any kind of function. i am not good in sql functions

please guide me
Posted
Updated 1-Feb-12 23:36pm
v2
Comments
Amir Mahfoozi 2-Feb-12 5:40am    
Your question is unclear. Please provide an example.

1 solution

It sounds like you want to concatenate the rows into a single cell. To do that do

SQL
DECLARE @RowsIntoCell NVARCHAR (MAX); 
SELECT @RowsIntoCell = COALESCE(@RowsIntoCell+ ',', '') + ColumnThatHasValues
FROM YourTable 


This will take all values from a column (ColumnThatHasValues) and comma delimit them into a variable named @RowsIntoCell
 
Share this answer
 
Comments
anoop_vip 3-Feb-12 5:03am    
hi thanks for your ans who i am going to use it in to siplay it in an table or something like that
ZurdoDev 3-Feb-12 7:47am    
Please explain better.
anoop_vip 5-Feb-12 13:24pm    
i mean suppose i want to display vendors, product type and products then by using sql join query i am able to do it but it would repeats rows for every products i donot wan to do that.now using your suggestion i am able to concatenate all products(particular to a vendor) in a variable but then how i am going to use this variable to display all three viz vendor,productstype and product ina tabluar format?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900