SQL Query - Syntax ( SQL 2005 / 2008 )

chokka
chokka used Ask the Experts™
on

I have a Table Name  - Medications

We have MedicationName - Column

I need to perform -

Select MedicationName from Medications

But " MedicationName " has values - [WORD1 WORD2 WORD3].

I need to pick only WORD1. I need to ignore all characters after space
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2010
Commented:
SELECT LEFT(MedicationName, CHARINDEX(' ', MedicationName + ' ') - 1) AS FirstWord
FROM Medications
chokkaStudent

Author

Commented:


Ok, Thanks Mathew, its working.

But i need to group by Member - FirstName.
 I know thats a seperate question. Can you please help me in that regards.

I am not able to group by Member Name
select	LastName + ',' + FirstName as [MemberName], 
		LEFT(Med.MedicationName, CHARINDEX(' ', Med.MedicationName + ' ') - 1) AS Medication,
		Med.Strength,
		Med.Quantity from members Mem
inner join MemberStatus MS
on MS.MemberID = Mem.MemberID
inner Join Medications Med
on Med.MemberID = Mem.MemberID
Where MS.Status = 'A'
and  Med.Active = 1

Open in new window

chokkaStudent

Author

Commented:
Thanks
Can you please help me in the Group By issue of this query also

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial