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 |
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2003-03-13 : 04:07:31
|
| I have a table called catlog the structure of the table is : catid int,catnamethere is a secont table prod whose structure is : prodid int ,catid int ,prodnamenow the records in table are like:catid catlogname1 A-abx2 A-rtx3 A-uyt4 B-sddr5 B-opt6 B-taxand the records in table products are as:prodid catid prodid1 1 prod12 1 prod2 3 2 prod34 4 prod45 3 prod56 5 prod6I want to write a query which can give me the count of the number of products for each main catalog like count for A=4 ,B=2any ideas?regards,Harshal.Expect the UnExpectedEdited by - harshal_in on 03/13/2003 04:13:18 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2003-03-13 : 04:16:35
|
| select left(c.catlogname,1), count(*)from products p, catlog cwhere p.catid = c.catidgroup by left(c.catlogname,1)if you may have more than one chanracter use charindex for the hyphon and maybe a derived table.Note this is a very bad design try.catid catlogname maincat1 A-abx Aorcatid catlogname maincat1 abx A==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
harshal_in
Aged Yak Warrior
633 Posts |
Posted - 2003-03-13 : 05:57:55
|
quote: select left(c.catlogname,1), count(*)from products p, catlog cwhere p.catid = c.catidgroup by left(c.catlogname,1)if you may have more than one chanracter use charindex for the hyphon and maybe a derived table.Note this is a very bad design try.catid catlogname maincat1 A-abx Aorcatid catlogname maincat1 abx A==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy.
thanks nr the query works just as i wanted.I had spent a few hours for the results.Thankyou.I have got u'r point regarding the design.thanks for the suggestion.regards,Harshal.Expect the UnExpected |
 |
|
|
|
|
|
|
|