Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: SQL query
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 5: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 at 14-Oct-12 12:52pm
   
thnk U very much......
Maciej Los at 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)



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