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 |
|
AskSQLTeam
Ask SQLTeam Question
0 Posts |
Posted - 2005-02-08 : 07:56:38
|
| Ranjith writes "Sir, My question is 'How do I select a single value from Multiplvalues' for ex. I Have a column by the name 'SURGEON' and in this column I have multiple values like 'dr sanjay/dr arun/dr babu' so when I am using the like pattern to retreieve a single value .say for ex. Dr Babu,It returns also 'dr sanjay/dr arun/.I want the sql query to retreive only DR Babu ,the other name should not be displayed..Thanks--Ranjith" |
|
|
Merkin
Funky Drop Bear Fearing SQL Dude!
4970 Posts |
Posted - 2005-02-08 : 07:57:55
|
| Redesign your database!Rule #1 of relational databases is that each column must contain a single piece of data per row.Damian |
 |
|
|
JimL
SQL Slinging Yak Ranger
1537 Posts |
Posted - 2005-02-08 : 10:41:32
|
| Sounds Like he needs to set up a relational sub table.JimUsers <> Logic |
 |
|
|
Seventhnight
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2005-02-08 : 11:32:45
|
While I agree that you need to learn more about table layout and design, I am not sure what the problem is...?for example...if you run a query with a where condition similar to:Select blah, surgeon from <table> Where surgeon like '%dr babu%'then you could just do:Select blah, surgeon = 'dr babu' from <table> Where surgeon like '%dr babu%'If it is dynamic it works the same:Select blah, surgeon = @surgeon from <table> Where surgeon like '%'+@surgeon+'%'Corey "If the only tool you have is a hammer, the whole world looks like a nail." - Mark Twain |
 |
|
|
Bustaz Kool
Master Smack Fu Yak Hacker
1834 Posts |
Posted - 2005-02-08 : 15:48:02
|
| See Merkin (Above)HTH=================================================================Egotism is the anesthetic that dulls the pain of stupidity. -Frank William Leahy, football coach (1908-1973) |
 |
|
|
Xerxes
Aged Yak Warrior
666 Posts |
Posted - 2005-02-08 : 16:00:03
|
| Perhaps Ranjith's column is omething like a memofile (in another language) or a column wherein commentary is stored. In that case, consider something like this...a dynamic searchdeclare @Doctor nvarchar(8000)declare @Pointer intSELECT SURGEON FROM DOCTABLEwhile @Pointer < 8000begin set @Pointer = @Pointer + 1 set @Doctor = substr(SURGEON,1,@Pointer) if @Doctor = 'dr babu' Break end set @Sequence = 0 endSemper fi, Xerxes, USMC(Ret.)----------------------------------------------"If cursors were nickels, I could park in town--all year!" |
 |
|
|
|
|
|
|
|