Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help with a select left statment 2

Status
Not open for further replies.
Dec 31, 2004
71
GB
Hi All,
I'm have a column that holds two values separtated by '-'

I have selected the right value by using the below SQL;

Select substring(EU_Department, (charindex('-',EU_Department)+1), 1000) as Team from dbo.TABLE

I'm attempting now to select the left value, I'm using the below but get the error message that the left function requires two arguments, can anyone point out what im doing wrong?

Select left(substring(EU_Department, (charindex('-',EU_Department)+1), 1000)-1) as Department from dbo.TABLE

Thanks

Nathan
 
Try this:

Code:
select substring(EU_Department,1,charindex('-',EU_Department)-1) from dbo.testtable
 
can anyone point out what im doing wrong?

Yes. You are only supplying one argument to the left function.

It's even simpler to use:

Code:
Select Left(EU_Department, charindex('-',EU_Department)-1)

Just be careful. This code will blow up if there is no - in the data.


-George

"The great things about standards is that there are so many to choose from." - Fortune Cookie Wisdom
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top