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
 New to SQL Server Programming
 sql statement

Author  Topic 

asm
Posting Yak Master

140 Posts

Posted - 2008-05-29 : 02:47:46
Table has a data like :
123,4567
1234,567
12,3456
12345,678

I want to retrive the data before the comma
like,
123
1234
12
12345

thanks

saurabh122
Starting Member

16 Posts

Posted - 2008-05-29 : 03:20:03
select substring(columnName,1,(charindex(',',columnName)-1)) from tableName
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-05-29 : 03:24:18
The data, is it stored as varchar or is it a numeric value?

1) select left(data, coalesce(nullif(charindex(',', data) - 1, -1), len(data)))
2) select floor(data)


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

raky
Aged Yak Warrior

767 Posts

Posted - 2008-05-29 : 03:25:19
SELECT LEFT(COLUMNNAME,CHARINDEX(',',COLUMNNAME)-1) FROM TABLENAME
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-05-29 : 03:50:36
SELECT COALESCE(PARSENAME(REPLACE(COLUMNNAME,',','.'),2),PARSENAME(REPLACE(COLUMNNAME,',','.'),1)) FROM TABLENAME
Go to Top of Page
   

- Advertisement -