Wednesday, March 28, 2012

Its possible make this..?

Hi to all...
I have three tables
Cards Card_Edition
Edition
CardID CardID
EditionID
Name_Card EditionID
Name_Edition
I would like to know if its possible to make a stored procedure to Add a new
card, take in count that each card has one or more editions, and each editi
on has one or more cards...
i would be grateful if you could pass to me urls, code, anything...
Thanks in advance
Josema.Not really sure what you want here
You have a card which has multiple editions and each edition has >=0 cards
in each edition?
OR
You want to know how many editions belong to a card?
Once you have this data what do you want to do with it?
The table design you have posted will not really help with the first
proposed meaning of what you want as all we can see here is that there are
Editions and Cards. Each Card may have >= 0 editions and each Edition may
have >= 0 cards
The second proposal will look something like
CREATE TABLE Card(CardID int identity(1,1) Primary key, Card_Name
varchar(50))
CREATE TABLE Edition(EditionID int identity(1,1) Primary key, Edition_Name
varchar(50))
CREATE TABLE Card_Edition(CardID int references Card(CardID), EditionID int
references Edition(EditionID))
INSERT Card(Card_Name) VALUES('A')
INSERT Card(Card_Name) VALUES('B')
INSERT Card(Card_Name) VALUES('C')
INSERT Card(Card_Name) VALUES('D')
INSERT Edition(Edition_Name) VALUES('First')
INSERT Edition(Edition_Name) VALUES('Second')
INSERT Edition(Edition_Name) VALUES('Third')
INSERT Card_Edition VALUES(1,1)
INSERT Card_Edition VALUES(1,2)
INSERT Card_Edition VALUES(1,3)
INSERT Card_Edition VALUES(2,1)
INSERT Card_Edition VALUES(2,2)
INSERT Card_Edition VALUES(3,3)
SELECT Card_name, COUNT(*) as AmountOfEditions
FROM Card JOIN Card_Edition ON Card.CardID = Card_Edition.CardID
GROUP BY Card_Name
If this is not what you require then please tell me what you require.
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"Josema" <anonymous@.discussions.microsoft.com> wrote in message
news:461F0EC1-E3BF-4F8C-B8AD-48740E011A37@.microsoft.com...
quote:

> Hi to all...
> I have three tables
> Cards Card_Edition

Edition
quote:

> CardID CardID

EditionID
quote:

> Name_Card EditionID

Name_Edition
quote:

> I would like to know if its possible to make a stored procedure to Add a

new card, take in count that each card has one or more editions, and each
edition has one or more cards...
quote:

> i would be grateful if you could pass to me urls, code, anything...
> Thanks in advance
> Josema.
>
|||And for another variation
How many cards are in each edition
select Edition_Name, COUNT(*) as AmountOfCards from
Edition JOIN Card_Edition on Edition.EditionID = Card_Edition.EditionID
GROUP BY Edition_Name
--
Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
www.allisonmitchell.com - Expert SQL Server Consultancy.
www.SQLDTS.com - The site for all your DTS needs.
I support PASS - the definitive, global community
for SQL Server professionals - http://www.sqlpass.org
"Allan Mitchell" <allan@.no-spam.sqldts.com> wrote in message
news:uub%23bB86DHA.2300@.TK2MSFTNGP10.phx.gbl...
quote:

> Not really sure what you want here
> You have a card which has multiple editions and each edition has >=0 cards
> in each edition?
> OR
> You want to know how many editions belong to a card?
> Once you have this data what do you want to do with it?
> The table design you have posted will not really help with the first
> proposed meaning of what you want as all we can see here is that there are
> Editions and Cards. Each Card may have >= 0 editions and each Edition may
> have >= 0 cards
> The second proposal will look something like
> CREATE TABLE Card(CardID int identity(1,1) Primary key, Card_Name
> varchar(50))
> CREATE TABLE Edition(EditionID int identity(1,1) Primary key, Edition_Name
> varchar(50))
> CREATE TABLE Card_Edition(CardID int references Card(CardID), EditionID

int
quote:

> references Edition(EditionID))
> INSERT Card(Card_Name) VALUES('A')
> INSERT Card(Card_Name) VALUES('B')
> INSERT Card(Card_Name) VALUES('C')
> INSERT Card(Card_Name) VALUES('D')
> INSERT Edition(Edition_Name) VALUES('First')
> INSERT Edition(Edition_Name) VALUES('Second')
> INSERT Edition(Edition_Name) VALUES('Third')
> INSERT Card_Edition VALUES(1,1)
> INSERT Card_Edition VALUES(1,2)
> INSERT Card_Edition VALUES(1,3)
> INSERT Card_Edition VALUES(2,1)
> INSERT Card_Edition VALUES(2,2)
> INSERT Card_Edition VALUES(3,3)
> SELECT Card_name, COUNT(*) as AmountOfEditions
> FROM Card JOIN Card_Edition ON Card.CardID = Card_Edition.CardID
> GROUP BY Card_Name
> If this is not what you require then please tell me what you require.
> --
> --
> Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP)
> www.allisonmitchell.com - Expert SQL Server Consultancy.
> www.SQLDTS.com - The site for all your DTS needs.
> I support PASS - the definitive, global community
> for SQL Server professionals - http://www.sqlpass.org
>
> "Josema" <anonymous@.discussions.microsoft.com> wrote in message
> news:461F0EC1-E3BF-4F8C-B8AD-48740E011A37@.microsoft.com...
> Edition
> EditionID
> Name_Edition
> new card, take in count that each card has one or more editions, and each
> edition has one or more cards...
>
|||Thanks Allan, your post was so useful...
Thanks Again.
Josema

No comments:

Post a Comment