Site Sponsored By: SQLDSC - SQL Server Desired State Configuration
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.
i want to display data from "Items" on the basis of Cat_Id(FK)..For Example: Category 1Item2 Item3 Category 2Item1 Item5 Category 3Item4 How can i do this in one Sql query/Procedure.... I've tried enough myself with different conditions and logics but in vain.... Please Help me.. Thanx in Advance...
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2013-05-15 : 05:46:08
you can use query like below
SELECT Cat_Name,Cat_Id,CAST(0 AS int) AS Item_IDFROM Category UNION ALLSELECT i.Item_Name,c.cat_ID,i.Item_IDFROM Items iINNER JOIN Category cON c.Cat_ID = i.Cat_IDORDER BY Cat_ID,Item_ID
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs
arslan
Starting Member
2 Posts
Posted - 2013-05-15 : 07:44:25
Thank you for the help Your ans gives me an idea and i've resolve my problem thanx
visakh16
Very Important crosS Applying yaK Herder
52326 Posts
Posted - 2013-05-16 : 00:23:13
welcome------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs