Click here to Skip to main content
12,624,895 members (36,754 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: SQL
how can i bind two tbls (returning by 2 select queries)
or
retrieve all these data(columns) in single tbl,
i mean that retrieve all these data in single tbl containing 5 coumns instead of 4 (with pname of 2nd select query)

create proc [dbo].[SpCateProducts](@cate_id int)
    as
begin
    select sb.subcate_name, sum(p.qty)
    from subcategory sb 
      join product p on p.subcate_id = sb.subcate_id
    where sb.cate_id = @cate_id
    group by sb.subcate_name
 
        select top 1 pname from product join subcategory
    on product.subcate_id=
    (
        select top 1 subcate_id
        from subcategory
        where cate_id=3
        order by NEWID()
    )
end
Posted 14-Oct-12 6:54am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Without the table schema (I remember your previous question[^], but still...) and their relations, and the specification of what you want exactly it is difficult to answer ("bind two tbls" is not even in English - despite the fact that has no meaning in sql).
Still, I have my ideas what you want. Try adding a subquery to your first one:

select sb.subcate_name, sum(p.qty), (select pr.p_name from product pr where pr.subcate_id = sb.subcate_id) as p_name
    from subcategory sb 
      join product p on p.subcate_id = sb.subcate_id
    where sb.cate_id = @cate_id
    group by sb.subcate_name
  Permalink  
Comments
ashokdamani 14-Oct-12 12:52pm
   
thnk U very much......
Maciej Los 14-Oct-12 13:07pm
   
Good work, +5!

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web01 | 2.8.161128.1 | Last Updated 14 Oct 2012
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100