[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

microsoft.public.sqlserver.programming

SQL syntax for LEFT/SEARCH scenario

unknown

3/28/2007 12:41:00 PM

Hi
I use this forumla in Excel to extract the left part of a string until first
space.
=LEFT(A1;SEARCH(" ";A1))

Is there any way to do the same in a SQL query as in

SELECT LEFT(fullname;SEARCH(' ';fullname) -- Which does not work.....
FROM tblpersons

Any hints appreciated.

Kind Regrads
Mr. Smith


2 Answers

Uri Dimant

3/28/2007 12:49:00 PM

0

Hi
DECLARE @st VARCHAR(20)

SET @st ='Hello world'


SELECT LEFT(@st, CHARINDEX(' ', @st)-1),
RIGHT(@st, CHARINDEX(' ', REVERSE(@st))-1)





"Mr. Smith" <nospam@nospam.com> wrote in message
news:em81mYTcHHA.1240@TK2MSFTNGP04.phx.gbl...
> Hi
> I use this forumla in Excel to extract the left part of a string until
> first space.
> =LEFT(A1;SEARCH(" ";A1))
>
> Is there any way to do the same in a SQL query as in
>
> SELECT LEFT(fullname;SEARCH(' ';fullname) -- Which does not work.....
> FROM tblpersons
>
> Any hints appreciated.
>
> Kind Regrads
> Mr. Smith
>
>


unknown

3/28/2007 6:42:00 PM

0

Great. Uri, thanks.

Kind rgrds
Mr. Smith

"Uri Dimant" <urid@iscar.co.il> wrote in message
news:%2341aoeTcHHA.984@TK2MSFTNGP04.phx.gbl...
> Hi
> DECLARE @st VARCHAR(20)
>
> SET @st ='Hello world'
>
>
> SELECT LEFT(@st, CHARINDEX(' ', @st)-1),
> RIGHT(@st, CHARINDEX(' ', REVERSE(@st))-1)
>
>
>
>
>
> "Mr. Smith" <nospam@nospam.com> wrote in message
> news:em81mYTcHHA.1240@TK2MSFTNGP04.phx.gbl...
>> Hi
>> I use this forumla in Excel to extract the left part of a string until
>> first space.
>> =LEFT(A1;SEARCH(" ";A1))
>>
>> Is there any way to do the same in a SQL query as in
>>
>> SELECT LEFT(fullname;SEARCH(' ';fullname) -- Which does not work.....
>> FROM tblpersons
>>
>> Any hints appreciated.
>>
>> Kind Regrads
>> Mr. Smith
>>
>>
>
>