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.
Author |
Topic |
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2007-09-21 : 06:17:25
|
I have a field in my data base as a file name which save as primarykeyid + '_' + filenameNow from the tsql i want's to just get the name of the fiel how can i get it via substring funtionSuppose in db it is saved as 12_Test.txt I want's Texst.txtor 1_Test_asdasdasd_sd.bmp I want's Test_asdasdasd_sd.bmpHow can i do this ?Kamran ShahidSoftware Engineer(MCSD.Net)www.netprosys.com |
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2007-09-21 : 06:20:56
|
[code]SELECT value, right(value, LEN(value) - CHARINDEX('_', value))FROM ( SELECT value = '12_Test.txt' UNION ALL SELECT value = '1_Test_asdasdasd_sd.bmp' ) t/*value ----------------------- ----------------------- 12_Test.txt Test.txt1_Test_asdasdasd_sd.bmp Test_asdasdasd_sd.bmp*/[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
kamii47
Constraint Violating Yak Guru
353 Posts |
Posted - 2007-09-21 : 07:09:38
|
Thnaks I just needed this right('Kamran_shahid_text.txt', LEN('Kamran_shahid_text.txt') - CHARINDEX('_', 'Kamran_shahid_text.txt')Kamran ShahidSoftware Engineer(MCSD.Net)www.netprosys.com |
 |
|
Kristen
Test
22859 Posts |
Posted - 2007-09-21 : 07:21:57
|
Note: You should use DATALENGTH() instead of LEN() in case the values have trailing spacesKristen |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2007-09-21 : 07:26:12
|
The problem happens when you use LEN on CHAR datatype columnMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|