Re: string from column value
From: Roji. P. Thomas (lazydragon_at_nowhere.com)
Date: 03/04/04
- Next message: Uri Dimant: "Re: Create View on a Remote Database"
- Previous message: Uri Dimant: "Re: Indexes and primary keys, from Delaney"
- In reply to: Louis Davidson: "Re: string from column value"
- Next in thread: Louis Davidson: "Re: string from column value"
- Reply: Louis Davidson: "Re: string from column value"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 4 Mar 2004 11:07:11 +0530
>>Samle data posted by the OP
name age_matches
-------------------------
bob bob
bob phil
bob joe
joe bob
joe rick
>>What is wrong with the schema?
Why you think this schema is OK?
I must admit that the OP had posted a simplified example.
Still I observed its a bad schema because...
1. This table doesnt have a primary key.
I know, for the sake of arguement we can assume that
name + age_matches is a combined primary key.
2. Duplicate Information.
name age_matches
-------------------------
bob bob
bob joe
joe bob
joe joe
To represent a single fact "Bob and joe are of same age"
we have four records here.
I guess that this information is probaly arrived from an Employee or
similiar table.
So to answer the real world question
"Give me the list of all employees who has the same age as Bob"
you can write a query like
SELECT empname FROM employees
WHERE Year(DOB) = (SELECT YEAR(DOB) FROM employees
WHERE empname = 'Bob')
Now, even if a derived table is required it should be
name age
------------
Bob 35
Joe 35
Which eliminates duplicates and easy to query.
My observation is based on my understanding
and my understanding is partly based on your book
Professional SQL Server 2000 Database Design :)
-- Roji. P. Thomas SQL Server Programmer "Louis Davidson" <dr_dontspamme_sql@hotmail.com> wrote in message news:%236xIsGJAEHA.1464@tk2msftngp13.phx.gbl... > Bad schema? What is wrong with the schema? > > -- > -------------------------------------------------------------------------- -- > ----------- > Louis Davidson (drsql@hotmail.com) > Compass Technology Management > > Pro SQL Server 2000 Database Design > http://www.apress.com/book/bookDisplay.html?bID=266 > > Note: Please reply to the newsgroups only unless you are > interested in consulting services. All other replies will be ignored :) > > "Roji. P. Thomas" <lazydragon@nowhere.com> wrote in message > news:%23$pg$VHAEHA.2632@TK2MSFTNGP12.phx.gbl... > > I am sorry to say that you have a bad schema. > > Anyways to answer your question, > > It is possible. > > > > You need to define a function which returns all the > > age_matches columns for a given name as a string. > > > > Then you can write something like > > > > Select name, dbo.ufn_agematches(name) > > From yourtable > > GROUP By name, > > > > > > > > -- > > Roji. P. Thomas > > SQL Server Programmer > > "sivrik" <anonymous@discussions.microsoft.com> wrote in message > > news:44BD7A47-9EE1-4D74-B66D-5BA1ADF7039C@microsoft.com... > > > Hey everybody, > > > > > > I have a table that looks like so: > > > > > > name age_matches > > > ------------------------- > > > bob bob > > > bob phil > > > bob joe > > > joe bob > > > joe rick > > > > > > I'd like to use a select to make the following table: > > > > > > name age_matches > > > ------------------------- > > > bob bob, phil, joe > > > joe bob, rick > > > > > > I'd preferably like to do it without using a cursor. Is this possible? > > > > > > TIA, > > > sivrik. > > > > > >
- Next message: Uri Dimant: "Re: Create View on a Remote Database"
- Previous message: Uri Dimant: "Re: Indexes and primary keys, from Delaney"
- In reply to: Louis Davidson: "Re: string from column value"
- Next in thread: Louis Davidson: "Re: string from column value"
- Reply: Louis Davidson: "Re: string from column value"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|