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.

 All Forums
 General SQL Server Forums
 Script Library
 How to read first and second character?

Author  Topic 

anabelle
Starting Member

19 Posts

Posted - 2010-02-01 : 03:56:13
I would like to do a query that will read first two characters on the Name Column withour specifying a character, it will just automatically display all the results of all first two characters. Ex.on
Name Column
Dexter
Marie
Joseph

RESULT should be
De
Ma
Jo

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-01 : 04:03:48
[code]SELECT Name,LEFT(Name,2) AS Result FROM Table[/code]

make sure you post this in t-sql forums in future.
This is script library intended to post working scripts
Go to Top of Page

anabelle
Starting Member

19 Posts

Posted - 2010-02-01 : 04:10:21
Ahmm...sori.thank you...
Go to Top of Page

anabelle
Starting Member

19 Posts

Posted - 2010-02-01 : 04:22:37
It gives me a null result for names to appear, all the names encoded datatype was varchar, when i run that script it gives me a null a value.

I tried to run that script again into another table that contains both number and character, instead of giving me the first two characters it gives me the total counted first two character in that column. Is there any other way to do it? to give me a result as mentione earlier?please...
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2010-02-01 : 04:44:12
if it gives null, it means for those records the value for column [Name] is NULL.

I don't quite understand the situation you have in another table. Can you post some sample data and the result ?


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-01 : 06:11:17
quote:
Originally posted by anabelle

It gives me a null result for names to appear, all the names encoded datatype was varchar, when i run that script it gives me a null a value.

I tried to run that script again into another table that contains both number and character, instead of giving me the first two characters it gives me the total counted first two character in that column. Is there any other way to do it? to give me a result as mentione earlier?please...


when it gives you null? what were contents of name column then?

ok, in such cases how will be format, will it be numbers and characters mixed?
Go to Top of Page

anabelle
Starting Member

19 Posts

Posted - 2010-02-02 : 04:40:29
i have executed the script on the Name Table that contain data examples:
Andrea Solis
Reynaldo Roch
Myrna Teh

and this is the script i run the one u gave
SELECT Name,LEFT(Name,2) AS Result FROM DataName

and the result was
NAME RESULT


(nothing show up)

Why it so?its purely text....




Go to Top of Page

senthil_nagore
Master Smack Fu Yak Hacker

1007 Posts

Posted - 2010-02-02 : 04:44:51
Is the data having spaces in leftmost???

if yes

SELECT Name,LEFT(ltrim(Name),2) AS Result FROM DataName

Senthil.C
------------------------------------------------------
[Microsoft][ODBC SQL Server Driver]Operation canceled

http://senthilnagore.blogspot.com/
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2010-02-02 : 04:46:02
Did you get results for this?

SELECT Name FROM DataName

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2010-02-02 : 05:06:48
quote:
Originally posted by anabelle

i have executed the script on the Name Table that contain data examples:
Andrea Solis
Reynaldo Roch
Myrna Teh

and this is the script i run the one u gave
SELECT Name,LEFT(Name,2) AS Result FROM DataName

and the result was
NAME RESULT


(nothing show up)

Why it so?its purely text....







are you sure you got nothing for name field also?
Go to Top of Page
   

- Advertisement -